PHP code for Order Total Minus Shipping
-
I am trying to pass the WooCommerce order total back to Facebook via thier tracking pixel.
Using this code in my functions.php file I can pass back the entire order total (product cost and shipping cost). But I want it to only pass back the product cost (order total without shipping).
// 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 }
Full details for implementing this piece of code can be found here: https://www.social-response.co.uk/facebook-conversion-pixel-woocommerce-values/
It is using
<?php echo $order_total ?>
to pass back the order total including shipping. What should I be using to pass back the order total without shipping?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘PHP code for Order Total Minus Shipping’ is closed to new replies.