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


BB Theme WordPress: A Comprehensive Review and Guide

Welcome to the world of BB Theme WordPress Are you searching for the perfect WordPress theme to bring your website to life? Look no further! BB WordPress Theme is here to help you design a […]


How to Delete a Theme in WordPress: A Step-by-Step Guide

Easy Ways to Delete Any Theme in WordPress Do you want to remove a WordPress theme and are looking for guidance on how to do it? Removing a theme can help declutter your site and […]


Salient WordPress Theme: A Comprehensive Guide for Beginners

If you’re looking for a WordPress theme that combines versatility, functionality, and style, the salient wordpress theme is worth considering. salient wordpress theme is a multi-purpose WordPress theme that caters to various niches, including business, […]