This code will track product purchase / checkout. Copy and paste below codes to your functions.php and don’t forget to change xxxxxxxxxx
with your own facebook pixel code.
<?php function woo_fb_pixeltracking( $order_id ) { $order = new WC_Order( $order_id ); $order_total = $order->get_total(); ?> <!-- Facebook Conversion Code 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', 'xxxxxxxxxx', {'value':'<?php echo $order_total ?>','currency':'IDR'}]); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/trev=xxxxxxxxxx&cd[value]=<?php echo $order_total ?>&cd[currency]=IDR&noscript=1" /></noscript> <!-- End Facebook Conversion Code --> <?php } add_action( 'woocommerce_thankyou', 'woo_fb_pixeltracking' ); ?>
The post Embed facebook conversion pixel for woocommerce appeared first on MySandbox.