/
Adding Facebook Conversion Pixel to Woocommerce Checkout
Adding Facebook Conversion Pixel to Woocommerce Checkout
An easy way to track conversion with Facebook or any conversion script is to add a small script to the thank you page with a hook. Add this to the end of your functions.php file. Insert and update your tracking code and adjust if you want to track values.
Need help?
If you need help to get this to work on your site please create a ticket and we'll do our best to offer some support. The code may not work for everybody and you may need to make some adjustments.
// FB Pixel Tracking Code
add_action( 'woocommerce_thankyou', 'fb_pixeltracking' );
function fb_pixeltracking( $order_id ) {
$order = new WC_Order( $order_id );
$order_total = $order->get_total();
?>
<!-- Start FB Tracking - Replace XXXXXXXXXXXXXX with your tracking ID to track orders with values-->
<!-- Facebook Conversion Code for Sales from Facebook Ads -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'XXXXXXXXXXXXXX', {'value':'<?php echo $order_total ?>','currency':'GBP'}]);
</script>
<noscript>
<img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/trev=XXXXXXXXXXXXXX&cd[value]=<?php echo $order_total ?>&cd[currency]=GBP&noscript=1" />
</noscript>
<!-- END FB Tracking -->
<?php
}
NB. UPDATE
Apologies to those of you who found the code not to be working. It is now fixed and updated here. Use the pixel helper tool from Facebook to check. Here are our results.
, multiple selections available,