Product specific code only loads on product page itself, not checkout (with FIX)
-
In this plugin, the product specific code loads on the product page, not on the checkout or thank you page. This defeats the purpose of the entire plugin, and causes huge errors in the numbers of conversions, which cost my client several thousand dollars in the first week until we determined the problem. Do not use this plugin.
If you need to load in a product specific conversion code, try this:
<?php // Load Tracking Pixel by Harlan T Wood & Adam Apollo // Facebook Tracking Pixel Code on Thank You Page for Specific Product // User adds -tp to product slug to load the conversion code function order_items_include_tracking_pixel($order, $order_id) { foreach ( $order->get_items() as $item ) { $product = $order->get_product_from_item( $item ); if ( ! $product ) { continue; } $sku = $product->get_sku(); if (preg_match('/-tp$/', $sku) === 1) { return true; } } return false; } function my_custom_tracking( $order_id ) { $order = new WC_Order( $order_id ); if (order_items_include_tracking_pixel($order, $order_id)) { $total = $order->get_order_total(); // INSERT TRACKING CODE or // DO YOUR CUSTOM BEHAVIOR HERE } } add_action( 'woocommerce_thankyou', 'my_custom_tracking' ); ?>
It can be inserted in Functions.php — just add “-tp” to the end of any product slug to load the tracking code or custom behavior on the thank you page. You can also change the specific text to be added to the slug on this line by changing the “-tp” to something else:
if (preg_match('/-tp$/', $sku) === 1) {
You do not need this plugin for this code to work.
https://www.ads-software.com/plugins/woocommerce-conversion-tracking/
- The topic ‘Product specific code only loads on product page itself, not checkout (with FIX)’ is closed to new replies.