Title: Adding tracking code to thank.you.php file
Last modified: August 31, 2016

---

# Adding tracking code to thank.you.php file

 *  Resolved [hcyan](https://wordpress.org/support/users/hcyan/)
 * (@hcyan)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/)
 * Hello, I am trying to add my google conversion code into the woocommerce/checkout/
   thankyou.php file via FTP, to track once a purchase is confirmed. Could someone
   quickly confirm where I am suppose to place the code snippet in the file? The
   instructions says to place between the </body> tags, but I don’t see “</body>”
   anywhere in the existing code in this php file. Please help?
 * Thank you!
 * I pasted part of the section from my thankyou.php file here that I think applies:
 * <p class=”woocommerce-thankyou-order-received”><?php echo apply_filters( ‘woocommerce_thankyou_order_received_text’,
   __( ‘Thank you. Your order has been received.’, ‘woocommerce’ ), $order ); ?>
   </p>
 *  <ul class=”woocommerce-thankyou-order-details order_details”>
    <li class=”order”
   > <?php _e( ‘Order Number:’, ‘woocommerce’ ); ?> **<?php echo $order->get_order_number();?
   >**
 *  <li class=”date”>
    <?php _e( ‘Date:’, ‘woocommerce’ ); ?> **<?php echo date_i18n(
   get_option( ‘date_format’ ), strtotime( $order->order_date ) ); ?>**
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 10 replies - 1 through 10 (of 10 total)

 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206255)
 * Suggest you don’t modify the template because any edits will be overwritten by
   updates.
 * WooCommerce provides a mechanism to do what you want by means of a hook. Make
   a child theme and put a function like this in functions.php for your child theme:
 *     ```
       <?php
         add_action ('woocommerce_thankyou', 'myfunction');
         function myfunction($order_id) {
           $order = new WC_Order($order_id);
           // output your tracking code here
         }
       ```
   
 * If you need further help, please post the google conversion code on pastbin.com
   and post just the link here.
 *  Thread Starter [hcyan](https://wordpress.org/support/users/hcyan/)
 * (@hcyan)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206393)
 * [@lorro](https://wordpress.org/support/users/lorro/) – thanks for the feedback
   and assistance. I actually don’t have the option to create a child theme at this
   time. I understand that whenever WC gets updated whatever changes I make will
   be overridden, but for now working in the template is my only option. Could I
   just create this hook in the main theme function.php file? Or if someone could
   show me where to put the code snippet in the woocommerce/thankyou.php file?
 * Appreciate any further input if any.
 * Thank you all!
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206395)
 * ^ functions.php is still a theme file. If you use code/functions you could alternatively
   make a custom plugin to house your changes.
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206416)
 * I think you need to enable with the child theme option if you want to put in 
   the tracking code. WooCommerce gets updated every few weeks and if you can’t 
   update, or it becomes a burden to do so, the site is likely to develop other 
   problems. Editing the core template is a dead end route.
 * There are several child theme plugins, maybe they will help:
    [https://wordpress.org/plugins/search.php?q=child+theme](https://wordpress.org/plugins/search.php?q=child+theme)
 * Otherwise I should come back to the tracking code issue later.
 *  Thread Starter [hcyan](https://wordpress.org/support/users/hcyan/)
 * (@hcyan)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206429)
 * [@mike](https://wordpress.org/support/users/mike/) – Hi Mike! Hope you are doing
   well. Thanks for the suggestion, I am not technical enough or have the experience
   needed to create a custom plugin, unfortunately 🙁
 * [@lorro](https://wordpress.org/support/users/lorro/) – Wow, I had no idea there
   were plugin’s to create child themes! Thank you for letting me know, I will look
   into this and get one installed asap.
    Once I do, I will have to see how the 
   plugin works in order to let me customize, and then figure out how to add the
   code for the hook you suggested previously in the child theme functions.php file.
   I will provide an update once I get this far. thanks!
 *  Thread Starter [hcyan](https://wordpress.org/support/users/hcyan/)
 * (@hcyan)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206462)
 * Hello – here is an update on the issue:
    I have installed a plugin that created
   a child theme (yay!) Through the plugin, I accessed my child theme’s functions.
   php file. I copied and pasted in the function code that lorro provided above,
   except for the last line. I replaced the last line (“// output your tracking 
   code) with my google conversion code. I hit update and got an internal error 
   500. So it didn’t like what I input. Btw – there is no active website called 
   pastbin.com.
 * I did this in my staging site, not sure if that would have mattered or not?
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206466)
 * Sorry for the typo: pastebin.com. Please put all of the code in your child theme’s
   functions.php in a paste, then post just the link here.
    Staging site should 
   not matter.
 *  Thread Starter [hcyan](https://wordpress.org/support/users/hcyan/)
 * (@hcyan)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206493)
 * Hi again – in an effort to keep things simple, and not mess with child them php
   files, could I just paste the google conversion code into the text box of my 
   Checkout page that I already have? This page was orginally created so that I 
   had a page set up for the woocommerce shortcode [woocommerce_checkout]. Could
   I just stick in the code in the next line after that shortcode? Or am I simplifying
   it too much and it needs to be in the thankyou.php file?
 * Thanks!!
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206494)
 * The checkout page does various things depending on the endpoint used, yet you
   will only want your code to fire when the endpoint is order-received, so that’s
   not going to work.
 * If you don’t use a child theme and choose to modify core WooCommerce template
   files, you will either lose your edits when you update WooCommerce, or you don’t
   update WooCommerce and will develop other problems over time as your version 
   becomes outdated.
 * Here are some plugins to look at. Not tried them myself.
    [https://wordpress.org/plugins/tracking-code-manager/](https://wordpress.org/plugins/tracking-code-manager/)
   [https://wordpress.org/plugins/woocommerce-conversion-tracking/](https://wordpress.org/plugins/woocommerce-conversion-tracking/)
   [https://wordpress.org/plugins/tracking-script-manager/](https://wordpress.org/plugins/tracking-script-manager/)
   Maybe others if you search.
 *  Thread Starter [hcyan](https://wordpress.org/support/users/hcyan/)
 * (@hcyan)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206507)
 * [@lorro](https://wordpress.org/support/users/lorro/) – thanks for the plugin 
   suggestions, I will give these a try and see if it works with my conversion code.
   Appreciate all your help on this thus far. 🙂

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Adding tracking code to thank.you.php file’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [google conversion code](https://wordpress.org/support/topic-tag/google-conversion-code/)
 * [thankyou.php](https://wordpress.org/support/topic-tag/thankyou-php/)

 * 10 replies
 * 3 participants
 * Last reply from: [hcyan](https://wordpress.org/support/users/hcyan/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/adding-tracking-code-to-thankyouphp-file/#post-7206507)
 * Status: resolved