我希望将WooCommerce变量“ OrderID”和“ Cart_total”传递到我们的广告跟踪平台中。
我收到了需要实施的跟踪代码,并且在将这些变量输入AdForm时遇到问题。
这是代码段,效果很好,我认为我没有正确包含变量。
/**
* @snippet Add Conversion Tracking Code to Thank You Page
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=19964
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.3.4
*/
add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page' );
function bbloomer_conversion_tracking_thank_you_page() {
?>
<!-- Adform Tracking Code BEGIN -->
<script type="text/javascript">
window._adftrack = Array.isArray(window._adftrack) ? window._adftrack : (window._adftrack ? [window._adftrack] : []);
window._adftrack.push({
pm: XXXXXXXX,
divider: encodeURIComponent('|'),
pagename: encodeURIComponent('conversion'),
order : {
sales: '$woocommerce->cart->get_cart_total();',
orderid: '$order->get_id();'
}
});
(function () { var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://track.adform.net/serving/scripts/trackpoint/async/'; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })();
</script>
<noscript>
<p style="margin:0;padding:0;border:0;">
<img src="https://track.adform.net/Serving/TrackPoint/?pm=XXXXXXX&ADFPageName=conversion&ADFdivider=|" width="1" height="1" alt="" />
</p>
</noscript>
<!-- Adform Tracking Code END -->
<?php
}
具体来说,我被要求提供以下变量:
sales: '$woocommerce->cart->get_cart_total();',
orderid: '$order->get_id();'
但是这些不起作用。不幸的是,我不是程序员(程序员正在度假)。我想我需要在某个地方调用变量。
答案 0 :(得分:0)
“收到的订单(谢谢)”页面上没有更多的购物车数据,因此您的意思是$order->get_total()
。您的代码中也有一些错误。
所以您需要:
WC_Order
参数中获取$order_id
对象尝试以下操作:
add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page', 12, 1 );
function bbloomer_conversion_tracking_thank_you_page( $order_id ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
?>
<!-- Adform Tracking Code BEGIN -->
<script type="text/javascript">
window._adftrack = Array.isArray(window._adftrack) ? window._adftrack : (window._adftrack ? [window._adftrack] : []);
window._adftrack.push({
pm: XXXXXXXX,
divider: encodeURIComponent('|'),
pagename: encodeURIComponent('conversion'),
order : {
sales: '<?php echo $order->get_total(); ?>',
orderid: '<?php echo $order->get_id(); ?>;'
}
});
(function () { var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://track.adform.net/serving/scripts/trackpoint/async/'; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })();
</script>
<noscript>
<p style="margin:0;padding:0;border:0;">
<img src="https://track.adform.net/Serving/TrackPoint/?pm=XXXXXXX&ADFPageName=conversion&ADFdivider=|" width="1" height="1" alt="" />
</p>
</noscript>
<!-- Adform Tracking Code END -->
<?php
}
答案 1 :(得分:0)
完美,这就像一种魅力!非常感谢您的帮助!
我可以给你买啤酒吗? :-D
亲切的问候, 标记