Skip to content

Instantly share code, notes, and snippets.

@stacklast
Created July 24, 2023 16:34
Show Gist options
  • Select an option

  • Save stacklast/32304f2d085ab566b0b5d008f901dbfc to your computer and use it in GitHub Desktop.

Select an option

Save stacklast/32304f2d085ab566b0b5d008f901dbfc to your computer and use it in GitHub Desktop.
Track WooCommerce conversions
<?php
add_action('woocommerce_thankyou', 'woocommerce_thankyou_adwords_conversions');
function woocommerce_thankyou_adwords_conversions() {
if (!$order_id)
return;
$order = wc_get_order($order_id);
if ($order) {
$order_id = $order->get_id();
$order_total = $order->get_total();
?>
<!-- Event snippet for Purchase conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'XX-XXXXXXXXX/ZZZZZZZZZZ',
'value': '<?= $order_total ?>',
'currency': 'EUR',
'transaction_id': '<?= $order_id ?>'
});
</script>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment