From 784747b55a78d059866b36bb518fc7c7ff38be4e Mon Sep 17 00:00:00 2001 From: Thomas Geiger Date: Wed, 18 Mar 2020 10:41:46 +0100 Subject: [PATCH] Fixed: decrease checkout step numbers 3 and 4 if shipping destination is set to 'Force shipping to the customer billing address' in WooCommerce. This way there will be no gap in Checkout behaviour report in Google Analytics. --- integration/woocommerce.php | 3 ++- js/gtm4wp-woocommerce-enhanced.js | 9 +++++---- readme.txt | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/integration/woocommerce.php b/integration/woocommerce.php index 4f737962..e1eefafc 100755 --- a/integration/woocommerce.php +++ b/integration/woocommerce.php @@ -218,7 +218,8 @@ function gtm4wp_woocommerce_addglobalvars( $return = '' ) { var gtm4wp_eec = ' . gtm4wp_escjs_boolean( (bool) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) . '; var gtm4wp_classicec = ' . gtm4wp_escjs_boolean( (bool) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) ) . "; var gtm4wp_currency = '" . esc_js( get_woocommerce_currency() ) . "'; - var gtm4wp_product_per_impression = " . (int) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION ] ) . ';'; + var gtm4wp_product_per_impression = " . (int) ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION ] ) . '; + var gtm4wp_needs_shipping_address = ' . gtm4wp_escjs_boolean( (bool) WC()->cart->needs_shipping_address() ) . ';'; return $return; } diff --git a/js/gtm4wp-woocommerce-enhanced.js b/js/gtm4wp-woocommerce-enhanced.js index b3910614..1f8ce55f 100644 --- a/js/gtm4wp-woocommerce-enhanced.js +++ b/js/gtm4wp-woocommerce-enhanced.js @@ -472,6 +472,7 @@ jQuery(function() { if ( is_checkout ) { window.gtm4wp_checkout_step_offset = window.gtm4wp_checkout_step_offset || 0; window.gtm4wp_checkout_products = window.gtm4wp_checkout_products || []; + var gtm4wp_shipping_payment_method_step_offset = window.gtm4wp_needs_shipping_address ? 0 : -1; var gtm4wp_checkout_step_fired = []; // step 1 will be the billing section which is reported during pageload, no need to handle here jQuery( document ).on( 'blur', 'input[name^=shipping_]:not(input[name^=shipping_method])', function() { @@ -516,7 +517,7 @@ jQuery(function() { 'ecommerce': { 'checkout': { 'actionField': { - 'step': 3 + window.gtm4wp_checkout_step_offset + 'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset }, 'products': window.gtm4wp_checkout_products } @@ -542,7 +543,7 @@ jQuery(function() { 'ecommerce': { 'checkout': { 'actionField': { - 'step': 4 + window.gtm4wp_checkout_step_offset + 'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset }, 'products': window.gtm4wp_checkout_products } @@ -580,7 +581,7 @@ jQuery(function() { 'ecommerce': { 'checkout_option': { 'actionField': { - 'step': 3 + window.gtm4wp_checkout_step_offset, + 'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset, 'option': 'Shipping: ' + _shipping_el.val() } } @@ -595,7 +596,7 @@ jQuery(function() { 'ecommerce': { 'checkout_option': { 'actionField': { - 'step': 4 + window.gtm4wp_checkout_step_offset, + 'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset, 'option': 'Payment: ' + _payment_el.val() } } diff --git a/readme.txt b/readme.txt index 011144af..1a94ecc2 100644 --- a/readme.txt +++ b/readme.txt @@ -261,6 +261,7 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So = 1.11.4 = * Fixed: fire gtm4wp.checkoutStepEEC and gtm4wp.checkoutOptionEEC events if there is only one shipping method available and it is hidden from the user +* Fixed: decrease checkout step numbers 3 and 4 if shipping destination is set to 'Force shipping to the customer billing address' in WooCommerce. This way there will be no gap in Checkout behaviour report in Google Analytics. * Updated: tested version number for WooCommerce = 1.11.3 =