Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created April 7, 2022 13:17
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 kimcoleman/1210a551bcdb3d4f53d49cfb58f75212 to your computer and use it in GitHub Desktop.
Save kimcoleman/1210a551bcdb3d4f53d49cfb58f75212 to your computer and use it in GitHub Desktop.
Add a session variable so we only push the ecommerce data to GTM on the first checkout, not any subsequent visit to the confirmation page.
<?php
/**
* Add a session variable so we only push the ecommerce data to GTM on the first checkout.
* Not any subsequent visit to the confirmation page.
*
*/
function pmpro_gtag_ecommerce_set_session( $user_id, $morder ) {
pmpro_set_session_var( 'pmpro_gtag_order', $morder->id );
}
add_action( 'pmpro_after_checkout', 'pmpro_gtag_ecommerce_set_session', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment