Nicola Mustone

Happiness Lead @ Automattic



Customize the Thank you page in WooCommerce

Update 17th August 2015: I released the free plugin WC Custom Thank You to automate what i wrote in this tutorial. Please check the plugin release article.


You should always be grateful to your customers and, obviously, thank them after they complete a purchase.

WooCommerce already does this for you. It redirects to the Thank you page after a successful purchase, but sometimes it’s just not enough for you.

What to do in this case?

The simplest thing to do is to redirect customers to another page with your personal thoughts and thank you message.

To do so, open the file functions.php located in wp-content/themes/your-theme-name/ and add this code at the end of the file:

With this code the customer will be redirected to a specific URL after he completes the purchase. But you may feel that still is not enough. It just redirects to a page, but then you miss the order summary table and other important features that WooCommerce provides through the default Thank you page

You can have these information too. Let’s see how to add them in your custom Thank you page.

Build the perfect Thank you page

Create a page in Pages > Add New. Add all the text, images, and stuff you need to thank your customers. Now it’s time to get your hands dirty, a lot dirty.

Download “Custom Thank you page”

custom-thankyou.zip – Downloaded 20507 times – 4.12 KB

Create a folder in your theme, if it does not already exist, and name it woocommerce. Inside this folder create a new folder named custom-thankyou. We will use this folder to put all the custom files used for the custom Thank you page. Inside the folder custom-thankyou create four files named

  • failed.php – it will be used to show a message to the customer when his purchase fails.
  • header.php – it will be used to show the order information to the customer, such as the date, the order ID, etc.
  • table.php – it will be used to show the order summary to the customer, such as the products purchased, the shipping costs, taxes, etc.
  • customer-details.php – it will be used to show the customer details such as the billing and shipping addresses.

Now open the file failed.php and add this code into it:

Then open the file header.php and add this code into it:

Again, open the third file, table.php and add this code into it:

And last, but not least, open the file customer-details.php and add this code into it:

All these files are completely customizable. I know, you need a bit of PHP knowledges but it’s something not so hard and you can easily understand where to change the various parts of the code, if you need to. But I split them like this just to be sure that you will not need to edit them. You will understand better why later in this tutorial.

Now you need to edit again the file functions.php. Open it with your favourite text editor and find the code we added at the beginning of this tutorial. Replace it with this code:

Be sure to replace {PAGE_ID} with the ID of the page you want to use for your Thank you page. After it, add this other code:

Also here, be sure to replace {PAGE_ID} with the ID of the page you want to use for your Thank you page. This code filters all the pages content and if the page ID actually looped is the same of your custom Thank you page, it will decode the order ID from the URL and fire some actions.

Finally add the last part of the code:

These functions include the custom templates created before when the main wc_custom_thankyou() function fires the actions.

I used intentionally the actions here. As you can see the actions are fired with priority 10, 20 and 30.
This means that between each template you have still nine priorities you can use to add your custom code. All the page content instead (the content written in the page editor in Pages > Edit the page) will appear before anything else.

Well, that’s all. Feel free to comment this tutorial and let me know what you think about it!

Happy thanking!

Download “Custom Thank you page”

custom-thankyou.zip – Downloaded 20507 times – 4.12 KB

Edit: Thanks to @claudiosmweb for improving a snippet in this tutorial.


Subscribe to This Blog

Receive new articles from this blog directly in your inbox! No spam guaranteed!

Join 669 other subscribers

268 responses to “Customize the Thank you page in WooCommerce”

  1. Hi Nicola
    Thanks for the code and the plugin – it works fine.
    Is it possible to add the woocommerce receipt info to a custom page? I have found out how to edit the thankyou template to show different info, and i can direct them to a custom page, but how do I make the custom page into a wc thankyou/receipt page?
    Thanks

  2. Reliobrix Consulting is a noticeable Property & Real Estate Consultancy in Delhi/NCR, set up in 2013 and working from Noida. Reliobrix Consultancy gives various scopes of consultancy benefits in land business, particularly in lodging and private undertakings. Reliobrix is an exceedingly rumoured firm and with its all around experienced experts it comprehends the centre need of its clients and gives proposal according to the prerequisite and spending plan.

  3. I’m trying to get this to work, but for some reason the page is blank. The console is clean, and I used the code from the download. What could be the problem?

  4. Hi Nicolai,

    thanks for this great info. I set up the thankyou page, no problem. What i would like to do is create a button wich give the order details, so is should not be showing on the thankyou page, only when someone clicks the ‘show order details’button on the thankyou page. I created a button on the custom thankyou page, wich triggers the wc_custom_thankyou function. Works just fine! But can you tell me how i prevent the order details from showing on the page? thanks!

    grtz
    dennis

  5. Hi Nicolai, great tutorial and the custom thankyou page works like a charm for me. There are two things that I need some help from you though:
    1/ I use Thrive architect to make the page design and content. I want to show the woocommerce table and contents under the page heading but above some of the other contents on the page. Is that possible and how to do it. Tried with $content = ob_get_contents() . $content; but nothing happens for me.
    2/ Can’t fire the Facebook Purchase event for this custom thankyou page. Any help will be much appreciated.
    Thanks again. Regards
    Svetlomir

  6. Hello Nicola,
    Really great tutorial but if you find some time to help me since I’m receiving error on functions.php on line 41 and I’m almost 100% sure that I followed all the steps. From creating subfolder in woocommerce folder on my child theme further on. I copy and paste all 4 functions editable scripts even though I dont need all of them but I wanted to see how it looks. I changed PAGE_ID as well but unfortunately I probably missed something.
    If there is some quick fix please assist because I’m just a rookie in WP , websites, coding, etc.
    Thank you in advance.
    Best,
    D.D.

  7. I use this cod, when copy snippet to function.php site not work

  8. Is this “hack” working with the latest version of WooCommerce? Also, why not just create a plugin that allows us to install and edit any custom text?

    1. That exists already, you can find it here: https://woo.com/products/custom-thank-pages/

  9. Please remove this comment because my last name is in it. 🙂 Thanks in advance

  10. Overall very nice, but the code generates several notices and errors with WP_DEBUG turned on. Would be nice if you re-visited it all again to make it work with WP 5.4 and WC 4.0.1.

  11. Hi

    i used your code and its working perfectly without force login before checkout.

    if i use force login before checkout after payment its redirect me to again checkout page.

    Please help me

  12. Hi friend, How do I do if a want to add to the thak you page a form from Caldera Forms or Contact Form 7 and hook into that form th order id. I will appreciate all your help. Kindest regards!

  13. Hi
    I followed your instructions to the “T” and already had my Thank You page created. When I checkout, I get redirected to my Thank You page but it does not show any of the order information.

    I don’t understand why I don’t and was wondering if you can think of what would be causing this.

    I’m working on the staging server testing there first. URL: https://diystagingenv.wpengine.com/thank-you-for-your-purchase/?order=19826&key=wc_order_hmCou2rehEmIY

    Much appreciate any guidance you can give me.

    Lyse

    1. I couldn’t make it work, so used your plugin. However your plugin has not been updated not tested in the latest versions WordPress nor WooCommerce.

      1. Hello there!
        Yes, I am aware that it is outdated. I do not have plans of releasing an update soon.

        I recommend checking this one: https://woo.com/products/custom-thank-pages/

        1. Thank you for the reply. I’d rather have a plugin that does not require yearly renewal costs. I fine using yours for as long a it will work.
          Lyse

Leave a Reply

You Might Also Like These Articles


Contribute to Improving This Blog

Did you enjoy this article? Was it helpful? Contribute to help me write more articles! The funds collected from this blog are reinvested directly into improving my skills or the blog so that I can provide more and better content!

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

€1.00
€5.00
€10.00
€5.00
€15.00
€100.00
€5.00
€15.00
€100.00

Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Don't Miss a Thing!

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Join 669 other subscribers

Continue Reading

Discover more from Nicola Mustone

Subscribe now to keep reading and get access to the full archive.

Continue reading