javascript - Pass order data to AdForm tracking code in Woocommerce thankyou
I am looking to pass along the WooCommerce Variables "OrderID" and "Cart_total" into our Ad Tracking platform.
I was supplied with the tracking code which needed to be implemented and am having issues getting these variables into AdForm.
Here's the snippet, which works perfectly, I think that I am not including the variables correctly.
/**
* @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 class="page_speed_70453105">
<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
}
Specifically, I was asked to provide the following variables:
sales: '$woocommerce->cart->get_cart_total();',
orderid: '$order->get_id();'
But these are not working. I am unfortunately not a programmer (the programmer is on holiday). I think I need to call the variables somewhere.
Answer
Solution:
There is no more cart data in Order received (thankyou) page, so you surely mean
$order->get_total()
. Also there is some mistakes in your code.So you need:
WC_Order
object from the missing$order_id
argument in your hoked functionTry the following: