WooCommerce Thankyou tracking code installation placement

故事扮演 提交于 2019-12-04 19:51:35

You can try adding the php tracking code inside the header.php (before the end of the head tag) or footer.php (before the end of the body tag). You need to get the id of the page if you want it to run exclusively on that page only.

Do something like this

if(is_page(yourpageidhere)):
//paste the tracking code here
endif;

UPDATED

Instead of overriding the thankyou.php template as you can see its source code there is this line:

<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>

Which means that you can use this woocommerce_thankyou action hook with a custom function, to output anything in this template line. First get the template clean of your code...

Also I have corrected your code in the image link, as it was not correct. You should use the following code in the function.php file of your active child theme or active theme:

add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );
function tracking_code_thankyou( $order_id ) {

    $random_number = time() . mt_rand(1000, 9999999);
    $current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
    $url = "https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=$randomNumber&epu=$currentPage&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]";

    echo '<em>Your tracking code just below (for testing)</em>
    <img id="1000143661_tester" src="'.$url.'" width="1" height="1" border="0" />';
}

It will output your code just after customers details at the end of the order-received page…

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!