Last active
December 17, 2018 13:46
-
-
Save jessepearson/4d3032972462c34dfdb460670062d0ee to your computer and use it in GitHub Desktop.
Will disable GA code for all WooCommerce pages excluding the order received page. Assumes WooCommerce is active.
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
<?php // do not copy this line | |
/** | |
* Will disable GA code for all WooCommerce pages excluding the order received page. | |
* @link https://wordpress.org/support/topic/same-web-property-id-is-tracked-twice-3/ | |
* @param bool $tracking_disabled Value being passed in, typically false. | |
* @return bool Value we need returned. | |
*/ | |
function maybe_disable_woocommerce_ga_tracking( $tracking_disabled ) { | |
if ( is_order_received_page() ) { | |
return $tracking_disabled; | |
} | |
if ( is_woocommerce() || is_cart() || is_checkout() ) { | |
$tracking_disabled = true; | |
} | |
return $tracking_disabled; | |
} | |
add_filter( 'woocommerce_ga_disable_tracking', 'maybe_disable_woocommerce_ga_tracking', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment