Created
August 28, 2018 07:14
-
-
Save nicomollet/812f63efb4dcfce0d84de1275c65fb59 to your computer and use it in GitHub Desktop.
Google Tag Manager for WordPress (DuracellTomi): Exclude orders with status failed
This file contains hidden or 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 | |
/** | |
* Google Tag Manager: Exclude orders with status failed (only paid statuses) | |
* | |
* @param $tag | |
* | |
* @return string | |
*/ | |
function googletagmanager_getthetag( $tag ) { | |
global $wp; | |
if ( function_exists('is_order_received_page') && is_order_received_page() ) { | |
if ( ! empty( $wp->query_vars['order-received'] ) ) { | |
$order = wc_get_order( absint( $wp->query_vars['order-received'] ) ); | |
// Order is not paid, remove the tag | |
if ( !empty($order) && !$order->is_paid() ) { | |
$tag = ''; | |
} | |
} | |
} | |
return $tag; | |
} | |
add_filter( 'gtm4wp_get_the_gtm_tag', 'googletagmanager_getthetag', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment