Skip to content

Instantly share code, notes, and snippets.

@elias1435
Created April 10, 2024 09:24
Show Gist options
  • Save elias1435/5d7248058650360f38a703c91e9b38c2 to your computer and use it in GitHub Desktop.
Save elias1435/5d7248058650360f38a703c91e9b38c2 to your computer and use it in GitHub Desktop.
Add tracking code only in woocommerce order received page
/**
* Add tracking code on Order received/thank you page.
*
* @return void
*/
function md_thankyou_page_tracking_code() {
if ( ! is_wc_endpoint_url( 'order-received' ) ) {
return;
}
?>
<!-- Event snippet for Purchase (1) conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'AW-000000000/000000000_000000000',
'value': 1.0,
'currency': 'GBP',
'transaction_id': ''
});
</script>
<?php
}
add_action( 'wp_footer', 'md_thankyou_page_tracking_code' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment