Loading twice WooCommerce thankyou page would duplicate Conversion tracking?
You can use order custom meta data to avoid duplicated Conversion tracking as follows:
add_action( "woocommerce_thankyou", "pixel_analytics_conversion_track_script", 20 );if ( ! function_exists( 'pixel_analytics_conversion_track_script' ) ) { function pixel_analytics_conversion_track_script( $order_id ) { // Avoid if pixel analytics conversion track script has been run before if ( $order_id > 0 && 'done' !== get_post_meta( $order_id, '_pixel_tracking', true ) ) { $order = wc_get_order( $order_id ); if ( is_a($order, 'WC_Order') ) { $order_id = $order->get_id(); // order id $order_key = $order->get_order_key(); // order key $order_total = $order->get_total(); // order total $order_currency = $order->get_currency(); // order currency $order_payment_method = $order->get_payment_method(); // order payment method $order_shipping_country = $order->get_shipping_country(); // order shipping country $order_billing_country = $order->get_billing_country(); // order billing country $order_status = $order->get_status(); // order status ?> <script type="text/javascript"> jQuery(document).ready(function( $ ){ console.log('PURCHACE EVENT'); /* Track conversion on facebook Pixel */ fbq('track', 'Purchase', { value: <?php echo $order_total ?>, currency: "<?php echo $order_currency ?>" }); /* Track conversion on Google Ads */ gtag('event', 'conversion', { 'send_to': 'AW-693771414/0MhwCMa9rLYBEJa56MoC', 'value': <?php echo $order_total ?>, 'currency': "<?php echo $order_currency ?>", 'transaction_id': "<?php echo $order_id ?>" }); }); </script> <?php // Flag the order (with custom meta data) to avoid pixel analytics conversion track script run multiple times. update_post_meta( $order_id, '_pixel_tracking', true ); } } }}
Code goes in functions.php file of the active child theme (or active theme). It should works.