Skip to content

Instantly share code, notes, and snippets.

@nicomollet
Created August 28, 2018 07:14
Show Gist options
  • Save nicomollet/812f63efb4dcfce0d84de1275c65fb59 to your computer and use it in GitHub Desktop.
Save nicomollet/812f63efb4dcfce0d84de1275c65fb59 to your computer and use it in GitHub Desktop.
Google Tag Manager for WordPress (DuracellTomi): Exclude orders with status failed
<?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