Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Last active December 17, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessepearson/4d3032972462c34dfdb460670062d0ee to your computer and use it in GitHub Desktop.
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.
<?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