Home » WooCommerce » Adding Event snippet for Purchase conversion with order total in WooCommerce

Adding Event snippet for Purchase conversion with order total in WooCommerce

Need to add Google conversion tracking code with order value in WooCommerce?

Today I’ll show you how to add Event snippet for Purchase conversion with order total. It’s simple, does not require any third party plugins, and will only take you a couple of minutes to do. No exceptional coding skills required.

Looking for tutorial how to add Event snippet for Purchase conversion without order value? Click here.

How to add Event snippet for Purchase conversion with order value in WooCommerce

Best WordPress hosting 2024

First thing you need to do if you want to add Google conversion snippet to WooCommerce – go to Appearance >> Theme File Editor or Tools >> Theme File Editor.

Once you’re there, click functions.php file on the right side of the page. When functions page is open, scroll to the bottom of the page, and add this function:

function rocksolid_thankyou_tracking( $order_id ) {
   $order_total = get_post_meta( $order_id, '_order_total', true); ?>
<?php }
add_action( 'woocommerce_thankyou', 'rocksolid_thankyou_tracking' );

This function is triggered when customer finishes checkout process. It also gets the total order value ($order total in the code).

Now we just need to add your Event snippet for Purchase conversion, and add that order value to the function. Here’s the complete example:

function rocksolid_thankyou_tracking( $order_id ) {
    $order_total = get_post_meta( $order_id, '_order_total', true); ?>

	<!-- Event snippet for Purchase conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-1119929/i8SmCN-qs6UYEJtwp',
      'value': <?php echo $order_total; ?>,
      'currency': 'EUR',
      'transaction_id': ''
  });
</script>
<?php }
add_action( 'woocommerce_thankyou', 'rocksolid_thankyou_tracking' );

You probably noticed where and how I’ve added order total 'value': <?php echo $order_total; ?>, in the code. Your function should be identical except send_to identifier (that’s your own conversion tracking code). You may also have different currency in the code.

Here how Google conversion tracking code with order value will look in functions.php file:

woocommerce add event snippet for purchase conversion page with order total

That’s it – once you save changes you’ll be tracking conversions in WooCommerce with order value.

Fathom analytics - privacy focused cookie-free website analytics

Most popular tutorials


Get our latest WordPress news and special offers from RockSolidWP!

Only useful WordPress and WooCommerce tips and tricks and exclusive offers for our readers once a month. No marketing nonsense.

Looking for reliable yet affordable WordPress hosting?
Hostinger is the way to go!

Get 10% OFF by using code IMAKEITWORK