Created
June 27, 2016 14:23
-
-
Save tankbar/e72df4c48bd91122779774ca9d006377 to your computer and use it in GitHub Desktop.
Facebook tracking pixel on Thank you page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Facebook tracking pixel on Thank you page | |
function fb_pixeltracking( $order_id ) { | |
$order = new WC_Order( $order_id ); | |
$order_total = $order->get_total(); | |
?> | |
<!-- Facebook Conversion Code --> | |
<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', 'XXXXXXXXXXX', {'value':'<?php echo $order_total ?>','currency':'SEK'}]); | |
</script> | |
<noscript> | |
<img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/trev=XXXXXXXXXXX&cd[value]=<?php echo $order_total ?>&cd[currency]=SEK&noscript=1" /> | |
</noscript> | |
<!-- END FB Tracking --> | |
<?php | |
} | |
add_action( 'woocommerce_thankyou', 'fb_pixeltracking', 30 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment