Add conversion tracking code in thank you page Woocommerce

  • July 18, 2022

Hi Guys

Today we are going to learn how to add conversion tracking code in order thank you page.

We will do this using custom snippet in function.php

 * @snippet       Conversion tracking code in thank you head Woocommerce
 * @author        Deep Prakash Goyal
 * @website

add_action( 'wp_head', 'wpexpertdeep_google_conversion_thankyou' );
function wpexpertdeep_google_conversion_thankyou(){
    // On Order received endpoint only
    if( is_wc_endpoint_url( 'order-received' ) ) :

    $order_id = absint( get_query_var('order-received') ); // Get order ID

    if( get_post_type( $order_id ) !== 'shop_order' ) return; // Exit

    $order = wc_get_order( $order_id ); // Get the WC_Order Object instance
    <!-- Event snippet for Purchase conversion page -->
      gtag('event', 'conversion', {
          'send_to': 'AW-XXXXXXXXXXXXXXXXXX', // Enter your tracking code here
          'value': <?php echo $order->get_total(); ?>,
          'currency': '<?php echo $order->get_currency(); ?>',
          'transaction_id': '<?php echo $order_id; ?>'

Related Post


Change “in stock” / “out stock” text in Woocommerce single product page

In this tutorial you will learn how we can change “in stock” / “out stock” text with the custom. We will use custom snippet for this. Just copy the above snippet and paste in your […]


Change product price in cart programmatically

Here we will learn, how we can change product price in cart programmatically. Add below code in your theme’s functions.php file


Fix Images and Broken Links by Updating Paths in WordPress

Today we will learn how to fix broken images link issue in WordPress, after migrating site from local server to live server or (one domain to another). This is a very common issue. The simple […]