Created
July 24, 2023 16:34
-
-
Save stacklast/32304f2d085ab566b0b5d008f901dbfc to your computer and use it in GitHub Desktop.
Track WooCommerce conversions
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 | |
| 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