• Resolved hcyan

    (@hcyan)


    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://www.ads-software.com/plugins/woocommerce/

Viewing 10 replies - 1 through 10 (of 10 total)
  • 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

    (@hcyan)

    @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

    (@mikejolley)

    ^ functions.php is still a theme file. If you use code/functions you could alternatively make a custom plugin to house your changes.

    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://www.ads-software.com/plugins/search.php?q=child+theme

    Otherwise I should come back to the tracking code issue later.

    Thread Starter hcyan

    (@hcyan)

    @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 – 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

    (@hcyan)

    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?

    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

    (@hcyan)

    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!!

    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://www.ads-software.com/plugins/tracking-code-manager/
    https://www.ads-software.com/plugins/woocommerce-conversion-tracking/
    https://www.ads-software.com/plugins/tracking-script-manager/
    Maybe others if you search.

    Thread Starter hcyan

    (@hcyan)

    @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.