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” – 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” – 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 651 other subscribers

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!


Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount


Or enter a custom amount

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

More Posts That You Might Like…

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

  1. […] to customize your thank you page from Nicola Mustone, as well as how to add GA tracking […]

  2. Thanks so much for this tutorial! I followed instructions exactly and get following errors:

    1) Checkout page doesn’t show order details, order total, payment options, or submit button. Basically the entire section below address is missing. Any idea why this is?

    2) When I try to login to I get this:

    “Warning: Cannot modify header information – headers already sent by (output started at /home/unitedc6/public_html/wp-content/themes/salient/functions.php:2) in /home/unitedc6/public_html/wp-includes/pluggable.php on line 1178”


  3. Hi Ed and thanks for reading!

    The number 1) is due to 2). Are you using the latest snippets? I updated it some days ago because of the error you are experiencing.

    Be sure that the add_filter snippets use templat_redirect and not woocommerce_thank_you.

  4. Hello

    Thanks very much for this post, this is quite interesting. Just a question though : I use WPML on my website to have several languages.
    If I just modify the functions.php as stated at the beginning of your post, it always redirect to the same page, whatever language I’m using. Any suggestion about what I should to to redirect to the page in the language I’m using?


    1. Hi Nicolas, thanks for reaching out!

      It’s possible, WPML has the constant ICL_LANGUAGE_CODE which return the current language, e.g. it or fr.

      Then based on that value you can redirect to a different page.

  5. Works perfectly, thanks !!

    1. You’re welcome 😉

  6. Hi,
    When a customer enters a different order number in the URL, he will see another customer personal information such as phone number or address. It is dangerous.

    In the original version of the URL is a key in this format: key=wc_order_0000000000000

    Can i add this value in the URL with Your mod?

    1. Hi Tadeusz,
      thanks for reading and for pointing out that breach.

      I fixed the code including the order key. Now the code uses both the order ID and the key. If they do not match, the order review from the 4 new templates will not appear.

      1. Thanks for the corrections, but it seems you corrected the code only in the downloadable zip and not on the page – some people just follow the code on the site and won’t download the zip (as I did). Anyways, this article helped me a lot.

        1. Hey Filip, thanks for pointing it out!
          Fixed now.

  7. Hello! Is this no longer compatible for 2.3 as I am getting a white screen when trying to add the 2nd part of this? I can make an end page, but I cannot have the custom templates or any information, it appears to be linked to the ” $order_id = absint( $wp->query_vars[‘order-received’] );
    $order_key = wc_clean( $_GET[‘key’] );
    wp_redirect( get_permalink( {PAGE_ID} ) . ‘?order=’ . $order_id . ‘&key=’ . $order_key );” part of the code which does not return properly and results in a white screen on a fresh install with no plugins running. We even attempted to create a non-WP page for a custom endpoint and then add in simply the order number as that is really all we need out of the process, but it refuses to provide that as it will not define the filter regardless of the code anymore.

    1. Hi Lisa,
      i just checked with WC 2.3.5 and it still works properly. Be sure to change {PAGE_ID} in your code or it will break.

      Also, i updated the template_redirect right now because it was causing the page to not show on sites using default permalinks.

      The snippet will update as soon as GitHub update the gist cache, in the meantime you can get the updated gist here:

  8. Ah, after turning debugging on, it just wanted the { } around the permalink ids to be ( ) instead – if anyone else gets the white screen of death ;). Thanks so much for the code and for all your helpful messages in the Woo forums also, it is great now that I worked out that one little thing!

    1. Lisa you should replace {PAGE_ID} with the ID of your custom Thank you page. The whole code will be (in example):

      wp_redirect( get_permalink( 50 ) . ‘?order=’ . $order_id . ‘&key=’ . $order_key );

      I’m glad you got it fixed!

  9. Hi, i use PayU Poland Payment Gateway Plugin.
    In PayU page i must set:
    Invalid return URL
    Success return URL
    and Reports URL
    In Succes URL i have:
    In Reports URL i have:
    But what i should set in Invalid URL? The same URL that is in Suces?

    1. HI,
      please check the doc for this:

      If you still need assistance about it, please open a ticket here:


  10. Hi Nicola,

    Thank you for this post. I follow exactly what you wrote here, no errors after that when i refresh my website. The problem is when i try to purchase, then i cancel it, it still show my Thank You page. Does it works that way?

    This is because i wrote a message in the thank you page that the order is being processed, bla…bla..bla..a positive message saying the order is being processed. But below that is showing negative message the order is not successful because i cancel the order process (with intention to try this thank you hack). The message is “Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.”

    It’s kind of confusing when customer read this page, above is saying the order is being processed even it was cancelled, and below is the right cancellation message.

    You can try it here –

    This is live website, you can try add to cart, checkout then cancel during payment to see what i mean here.

    What should i do? Remove the static “your order is being processed” in this Thank You page?

  11. Hi there,

    I’m new to wordpress and have zero design background so I’m having to teach myself as I go. This question may be redeundant based on the terms other people are using so I just want to make sure that I’m clear. The link to the website is my test site that is no live. The problem that I’m having is that when I place my order, I’m led back to the check out page and the order details are underneath. The reason this doesn’t work is that I have a warning about lead time on my check out page telling customer to view our calendar before placing the order and so it is confusing to see this again after the order is placed.

    I suppose I could just add the verbiage I want to the terms and conditions but who actually reads those? I just don’t want people to order not being aware of our lead time and then request a refund later which just means more work for me that could have easily been avoided if the customer was fully aware.

    You can test this on our site by placing a check order if this is not clear.

    Hope this helps and that you can help!

    Thanks and blessings!

    1. Hi, you could add a checkout field and mark it as required so people will have to write a date in it before to place the order.

      You can use this plugin to add the field:

  12. Hi, thank you so much for the great tutorial
    your tutorial is the only one willing to guide by “holding hand”
    and for me who starting to learn about wordpress, php, html, css for less than a week is HUGE help.
    i have encounter some problem hopefully is just because of my stupid newbie mistake
    this is the detail of my setup
    os: win7
    server : wamp
    theme : Flatsome
    file structure:

    I put everything exactly as your instruction above
    and replace the {PAGE_ID} with ID which is in my localhost is 2717
    Now the custom thank you page wont show anything in the page
    i have several screenshot that hopefully can clarify my situation but im not sure should i post the link here or not and maybe use the HTML tag ?

    Again best wordpress tutorial website around !

    1. Hi Erik thank you very much for reading and for following me!

      Can you replace the following in your wp-config.php file please

      define('WP_DEBUG', false);


      // Enable WP_DEBUG mode
      define('WP_DEBUG', true);
      // Enable Debug logging to the /wp-content/debug.log file
      define('WP_DEBUG_LOG', true);

      Then please visit the page which is supposed to show an error (the blank page). You should see the text of the error. Please post it here!

      1. Thank you for coming back to me !
        and in such a short notice too 😀
        as soon as i enable the debug mode
        the top part of the website shows some error table

        and i cant even reach the checkout page..
        but if i disable the debug mode everything went back to normal O.o
        this is the debug log

        1. The issue is that something else (theme or plugins) are throwing errors. That said, these errors appear before the template_redirect which make it break.

          Please try switching to the Twenty Twelve theme to see if the issue persists. If so, then we can rule out an issue with the theme.
          I also recommend that you disable all plugins but WooCommerce when troubleshooting to rule out any conflicts there.

        2. Wait… something strange happen… all of sudden now the page working correctly
          the page im talking about is the custom Thankyou page
          now the page shows all the parts from
          Table.php header.php customer-details.php etc
          yay ! thank you ! lol
          im sorry for the earlier confusion but everything seems to be working as intended now
          again thank you so much for you brilliant tutorial !
          you sir got a lifetime fan 😀

  13. 1 more thing, may i ask for a rough direction as to where i can learn the php (i think?) i needed to make this kind of styling work for the custom ThankYou page
    this is the result page from your code

    and after i modify the “looks” using ms-paint
    essentially im trying to find out how to make a “columned content”? (im not sure if thats the right word)
    and put several of the parts side by side
    cheers !

      1. Thank you again Nicola !
        you truly are a life saver 😀

  14. Nicola,

    Thanks again for your help and the wonderful code, yes, I took you too literally and just changed out the page ID and left the brackets at first. It is working great now. However, one other thing that I was wondering as I have spent way too much time trying to customize this ;). We are just using the header part of the code to output the order ID, date, etc. on that thank you page. However, we have a lot of instructions for our clients in the content of that page, and they can’t actually see that header text and therefore their order number without scrolling way down as it outputs below the content, below the fold. I have tried flipping everything around every which way to get the header to output *before* the content of the thank you page, so it would be the little table with the order id, date, etc, then have our custom content. Nothing so far has worked in any version of the code that I have tried, any ideas?

    Otherwise, any ideas to at least bring the order ID into the page content of that thank you page without using a plugin for code? Then we could say “Thank you for your order, please use your custom #_____ when writing to us” or something like that at least?
    Using the code tags in WordPress does not work, unfortunately, it just strips out the php, already tried that one too. Really do not want to run yet another plugin just to be able to use one line of code in there to have an order ID number, there has to be a better way to do this and I am just missing it, right? I defer to your expertise if you have a moment of time. Thank you so much.

    1. Hi,
      you can easly switch the content and the other parts of the templates changing this code

      $content .= ob_get_contents();
      	return $content;

      with this

      $new_content = ob_get_contents();
      return $new_content . $content;
  15. Ah ha!! Thank you so much, you are so kind, that is perfect!!

    1. You’re welcome 🙂

  16. Is there any way I can just add some simple text to default thank you page? I do not see template file looking like thankyou page in template folder.


    1. Hi, sorry i missed this comment.

      The template you are looking for is view-order.php!

  17. Hi Nicola,
    I am very new to WP and only know very basic CSS and PHP…I was wondering if you could tell me how I can remove the bank account info that is shown on the order-received page as well as how I can get more space in between the different sections(by default, all the text and order information is very tight together).
    I have asked in various support forums but haven’t gotten any replies.

    Thank you so much!

    1. To remove those details you should empty all the fields of the bank account in your payment gateway settings.

      how I can get more space in between the different sections(by default, all the text and order information is very tight together).

      You should ask this to your theme developer. He will know what code to use!

  18. Hi Nicola,
    thank you for your reply, but if I remove all the bank info, it won’t show up in the Woocommerce emails either and the customer will never know where to send the money to!
    And regarding the margins and paddings on the chekcout page: I have asked my theme developer, but they said this is Woocommerce related and I should contact them…which I did but never got a reply…


  19. Hello! I fiund your tutorial searching a way to customize checkout page on wc. Do you make customization for clients? Can I contact you in private to explain you what I need so you can send me a quote? Thanks.

    1. Hi Alan,
      no i’m sorry i don’t usually do customizations for clients.

      You can seek help from an Affiliated Woo Worker or post a job on Codeable, I have provided links to these below.

      1. Thanks again. Just a question: can I “hide” the custom thank you page to users/visitors of site and display only when order is completed?

        1. Just don’t add it to any menu. It’s hard that a user guesses the URL. Also, if he does, the page will only show the text you added manually. All the rest of the content will not be shown to anyone which is not who placed the order.

          The default Thank you page works the same way.

        2. Thanks again.

  20. Hi again and thanks for you tutorisls. I’ve 3 membership products on my next wp site to sell, one of them is free. Can you link me or explain if possible how to relabel the ‘place order’ for this kind of products (membership) and how to skip the checkout for only the free membership product? Thanks again.

  21. Hi, thanks for this article, it is exactly what I was looking for. I’m just trying to redirect to a thank you page, so tried the first section of code exactly as you have it, but I’m receiving the following error now

    Fatal error: Call to undefined function is_checkout() in /nas/wp/www/staging/procenter/wp-content/themes/x-child/functions.php on line 43

    Any ideas?

  22. Hi, this are the elements showing up on my new the thank you page:

    Order: 100
    Dato: 24/04/2015
    Total: kr 147.00
    Payment method:

    Other elemts are missing…
    Any ideas why ?

    1. Be sure that everything is up to date and that the file names and paths are correct.

  23. Thank you so much for this great feature! Everything looks fine, but there is every time this message that says: “Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.” – What is this and can this be removed? I only offer bank transfer and PayPal at this moment..
    And how would it be possible to output my bank details?

    Hope you find time to help me, this would be really appreciated, many thanks in advance,

    1. oooops, sorry, I just noticed that I’ve copied the failed content into the header 🙂
      Anyway, is there a possibility to show my bank details?
      And one general question: If I only offer PayPal and Bank Transfer – would it then be possible at all that an order fails? I am thinking about customizing the failed.php to fit my needs..
      Many thanks again in advance!

      1. To show your bank details add them in your settings in WooCommerce > Settings > Checkout.

        Yes it’s possible that a PayPal order fails.

        1. Thank you ! I have added the details and on the original thank you page, they are shown. Not so on yours, thats why I was asking..

  24. You are a gem. Thank you for your time!

    1. Thank you too for reading!

  25. thanks for your great tutorial. But for some reason it is not working for me. I have created a woocommerce directory the pasted your custom-thankyou folder inside it. then added the code from your functions.php to my theme functions.php. I have created the thank you page and also added the PAGE ID in the functions.php . But it is not working. It is redirecting me to the cart page after check out. What should I do now? I am using woocommerce 2.3.9

    1. Hi,
      check the page ID and be sure that it’s correct.

      Please try switching to the Twenty Twelve theme to see if the issue persists. If so, then we can rule out an issue with the theme.
      I also recommend that you disable all non-Woo related plug-ins when troubleshooting to rule out any conflicts there.

  26. thank you very much for your reply. yes on of my plugin is causing the issue.

    1. Nice, thanks for letting me know! Hope the plugin author can fix it!

  27. Hi Nicola,
    thank you for this tutorial.
    I have a question though: I created a thank you page and did not copy all the customer details etc. into it because I simply wanted a Thank you page that just says Thanks, and doesn’t include all the othet details.
    Now I am wondering though: I only offer bank transfer and Paypal, and with bank transfer the purchase can’t fail, but what happens if Paypal payment fails? Would a customer still get send to my regular page as I haven’t set anything in case payment fails?

    Thank you!

  28. Thank you so much for this tutorials.
    I did exactly what you wrote. I added this code in the end of the file:

    add_action( ‘template_redirect’, ‘wc_custom_redirect_after_purchase’ );
    function wc_custom_redirect_after_purchase() {
    global $wp;

    if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
    wp_redirect( '' );


    but when i test it so is redirect me to the cart page and not to the thank you page that i created.

    Can you tell me what im doing wrong ?

    1. Hi Guy

      Please make sure that the “order received” in “woocommerce-setting-Check out Pages” don’t left a blank spaces

      Mostly = order received
      Should be changed to “order-received”

      Hope this work for you

  29. wauw..
    I was looking for ages for exactly this. thank you so much!!

    1. You’re welcome 🙂

  30. Hello! Thanks for detailed tutorial!
    I’ve done all step by step, but custom thankyou page actually it’s not working. After submitting an order user redirects to the page, but there is no order details.
    I think I have incorrectly submitted page ID in functions.php, can you help me to do it right?
    Link to custom page looks like this:
    So I need to replace {PAGE_ID} in functions.php with 1073, or with page_id=1073 ? Or something else? I’ve replaced with just 1073 and it’s not working.


  31. Pasting in the code from functions.php to the themes functions.php caused a white screen – fixed by removing the leading <?php tag.

  32. Unfortunately once this is installed the checkout just spins the loading icon and never loads. Not working under my setup.

    Ah well. I’ll find another way to do something WooCommerce could have done in 15 seconds with shortcodes.

    1. There must be another error. Please check all your code and be sure that you didn’t miss anything.

      WooCommerce can’t simply include this in the core since it’s a feature that not all users need to use.

  33. Wow, what a huge response since we first started this Nicola! Looks like I wasn’t the only one looking for this and I hope Woocommerce pays attention to allow people to customize the checkout pages again.

    I’m wondering, do you know of a way to add “share this” buttons on the thank you page? I want to be able to allow the customer to social share to Facebook, twitter, etc with details of their purchase. (example: “I just purchased xxxxx from”)

    Too bad Woocommerce doesn’t have a plugin for this!

    tags: how to add social share buttons on woocommerce checkout order confirmation thank you page.

    1. Hey Ed,
      yeah this is the most read article on my blog xD

      To add the share buttons, i suggest to add a plugin and then print them with a shortcode, or use the share module in Jetpack.

  34. Thanks for the tutorial. however, i try to implement your code but is not redirecting me to my custom thank you page.

    1. Hi Niyo,
      please double-check all the steps. Something probably is missing/wrong. As you can see a lot of people got it working, so the snippet looks to be correct.

      Double-check everything and then let me know if you find something.


  35. Hi,

    How do you avoid the custom thank you page from directly accessible multiple times even there’s no success order? Because I have added a facebook tracking on the thank you page but I don’t want users visiting the thank you page multiple times.


    1. Hi,
      That page is used multiple times, not only one. You can access it to view past orders, to pay if the order is still unpayed, etc.

      You could add a check to know if that’s the first time the customer visited the page, if not, don’t print the pixel code.

  36. Great, this is a nice plugin tweak if you don’t want to lose the changes you made to your plugin files after updating it. In past I made changes to plugin file but now I will try this.

    Thanks for sharing Nicola.

    1. You’re welcome Niki!

  37. Hi Nicola,
    First of all, thanks for your great tutorial.
    That helped me so much.
    However, I’ve got now an issue concerning the cart.
    Actually, after a checkout I’m well redirected to the good custom thank-you page but the cart is not emptied.
    Then, I’ve made a new checkout with the original code from Woocommerce and it works.
    I don’t why but with your code, carts are never emptied after checkout by my side. Do you have any idea about this issue?
    Thanks a lot for your help.

    1. Hi Frédéric,
      i just tested this with the code in the downloaded zip, and my cart is emptied.

      I tested with Storefront, maybe is your theme?

      1. Nicola,
        Actually I use a custom theme.
        I don’t know why but I can’t manage to empty the cart with your code … I added this code

        global $woocommerce;

        Inside the function wc_custom_thankyou (part “The order is successfull – print the complete order review”).
        Now it works … can’t explain why 🙂

        1. I’d use WC() instead of $woocommerce for better compatibility. We don’t use the global object from a while and its support will be probably dropped in the future.

        2. Thanks for the advice Nicola.
          However, I’ve found this peace of code on the woothemes site. It should be changed?

        3. Yes it should be changed. You can submit a report directly from the page where you found that code, informing the documentation team that the code needs to be updated, or send me the page link so i can do that myself.

          As you prefer.

        4. Just found it!
          Actually, that’s like yours.
          It’s a page with a link which drives to an external site.

          Thanks for your help Nicola

        5. Ah ok, it’s an article on Remi’s blog, i can’t do that much about it. It’s not in the internal documentation.

          You can send him a message or comment directly on his blog.

        6. Fine!
          Will do it this day.
          Really thanks for your help Nicola.

  38. Thanks for this! I only needed the very first function, but still very useful, cheers.

  39. Good day! I could have sworn I’ve been to this site before but after
    checking through some of the post I realized it’s new to
    me. Anyhow, I’m definitely happy I found it and I’ll be bookmarking and checking back frequently!

    1. Hey there!
      Thanks a lot and welcome 🙂

  40. Hey, you?re the goto expert. Thanks for haingng out here.

    1. Thank you for reading Mathew!

  41. My thank you page has an affiliate banner at the bottom of the page. How can I insert the WooCommerce content above that banner, so the banner can be at the bottom?

    Thank you so much in advance.

    1. Hi Jake,
      thanks for reading!

      You need to change this code

      $content .= ob_get_contents();

      To this

      $content = ob_get_contents() . $content;

      This will print any content you write in the page after the Thank you content from WooCommerce.

  42. Hi Nicola,

    great tutorial – thank you! I have two questions:

    I have learnt how to add extra fields to the products backend. Can I access the content of those fields in a standard fashion, or what do I need to consider?
    Can the content of the (text) fields – in my case it’s a custom order confirmation text per product – contain variables/placeholders, so that the text is completed with -say- a download link, login instructions etc?

    1. Hi Helmar,
      yes you can access them in the standard way. They are custom fields added to the order, so use the order ID to access them.

      I don’t understand what you mean here

      Can the content of the (text) fields – in my case it’s a custom order confirmation text per product – contain variables/placeholders, so that the text is completed with -say- a download link, login instructions etc?

      Can you explain?

  43. […] Mustone beschreibt in seinem Blog ausführlich, wie sich in WooCommerce eine individuelle Danke-Seite einrichten lässt und wie du […]

  44. @Nicola Thank you so much for your help!

    Can you please check out this page and see what I am talking about.

    I want to insert the woocommerce stuff right above the bottom banner but below the “Please spread the work” button.

    Thank you,

    1. Hey Jake, I can’t see your website, I receive this error:

      1. Please try it now.

  45. Hi Nicola,

    I’ve installed your plugin. Creating a custom thank you page with Contact Form 7 setup. I need the customer name, email and order id automatically pulled from the order details so that the customer just fill the remaining portion of contact form.

    Please help advice on how this can be done.

    1. Hi Ben,
      i’m not sure about how to achieve that since I don’t use Contact Form 7 and I never looked at its code, but you can get those information before the customer purchases the product and reaches the Thank you page. You could use this extension: – You also will need to purchase a license of Gravity Forms.

  46. Nicola, any luck accessing my website again?

    Thank you,

    1. Yes, I don’t see any bottom banner though. I see the button “Spread the word”, but after that there’s the website footer, not a banner.

  47. Strange.. What browser are you using? It works on Chrome and Safari.

    Anyone else?

    1. Nicola, any luck? Maybe even though you can not see the banner/image at the bottom of the screen, you can assume that it is there.

      How would I insert all the woo commerce stuff right above it, but below the button “Spread the word”?

      Thank you in advance,

  48. Hi,
    I’m trying to download the zip but the link doesn’t work anymore. Can you please update? This function would be great and I rather take the zip than the code version to avoid errors.

    thanks a lot.

    1. Hi Amir, thanks for reporting the issue! I’m going to fix it immediately.

      Anyway I’d suggest to use the plugin instead of the code in this article.
      It works, but the plugin is easier to use and updated for WooCommerce 2.4 already.
      You can find it here:

  49. Awesome. Any way to add fuction to hide the custom thank you page from local store search… We need to add message only for fully paid customers to follow link to project form to fill out, outside store. Obviously we dont want folks to get to the custom thank you unless order fully paid? Any thoughts on that? Thanx. ?

  50. Hi,

    Can I add page URL at the place of id see below.

    if ( ! is_page( {PAGE_ID} ) ) {
    return $content;

    At the place of {PAGE_ID} I need to add page name like {thank-you} as my theme des not allow me to create a page with page id.

    Please let me know.

    Thanks in advance..

    1. Hi, yes you can use the page slug.

      my theme des not allow me to create a page with page id.

      That looks really weird. This is not handled by the theme but by WordPress. I’d say that this is impossible. Anyway you can use the page slug or page title as I said above.


  51. Thanks for this tutorial and code. This has really helped me get a head start.

    In my specific case, I find that Woocommerce by default can display repeating information.

    1. You’re welcome! Glad you like it!

  52. I would prefer to use the plugin you created on my site, except I am using LeadPages for my Thank You page…The LeadPages page is not an available to choose with the plugin.

    Instead I used your code snippet and it worked perfectly, except that I did not get an email with my purchase information after I checked out. Is there a solution to this?

    1. Ignore my comment above…my order confirmation finally came…it just took a while! Thanks for sharing the plugin and code!

  53. Hello,

    Great article and eventually I will setup a full customization using your code and instructions.

    Wondering if there is a way to simply re-order the thank you page. By default, WooCommerce has the “Thank You. Your order has been received text.” at the top of the page and adds the interac email transfer instructions to the bottom of the page (below shipping address/billing address). Is it possible to move these details above the default thank you text?

    Thanks in advance,

    1. Hi Scott,
      Like I wrote in the article:

      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.

      Which means that you can change the priorities in the code to reorder them as well.

  54. Thank you for creating this plug-in! This is exactly what I needed! …but I cannot make it work..
    I have tried a lot of guides on this subject, but none of them worked, not even your plug-in.

    Issue: After ordering, the customer are redirected to the shopping cart (which now is empty). There is nothing that tells them that they have done a successful order.

    Is there anything in your plug-in that is hard coded – like “shop” or shopping cart or checkout – mine is written in norwegian, so I would have to change the php coding to match this – but is this the problem? I have tried changing the endpoints to the default, but it didn’t help either. Sorry for my lack of programming skills.

    Any help or tips would be appreciated.

    Kindest regards,

  55. When returning from paypal to the site I get a “The page isn’t redirecting properly” error. I found these in my debug log which didn’t exist before implementing this plugin:

    PHP Notice: Undefined variable: output in wp-content/themes/optimize/includes/theme-functions.php on line 41

    PHP Warning: wp-content/themes/optimize/functions/admin-hooks.php on line 160

  56. my downloadable products have not resuming feature. What can i do?

  57. Hi Nicola,

    This is an awesome article. Thank you!
    Everything works great, except one thing. When the custome thank you page appears, everything is visible, EXCEPT the product download link(s). (I have only downloadable products).

    When I refresh the page (F5), the download link(s) are there and everything looks fine.

    What can that be?


    1. Hi Maurice,
      That is not caused by this customization. The problem with that is the IPN from PayPal which I imagine is your payment gateway.

      The cause is that the IPN is not always immediate in returning a response to your website when a payment is submitted, so the links are not always available immediately, but when you refresh the page, the website received the IPN response and shows the links.

      To fix that you will need to enable PayPal PDT. You can find details about this issue and how to enable PayPal PDT here. Scroll to the section “Why don’t customers see the link to download products after paying and getting redirected back to my website?”.

  58. Hi Nicola,
    very thanks for this good tutorial 🙂

    Unfortunately for me it doesn’t work if we use the “Automatically Complete Orders” :

    In effect, If I custom Redirect after purchase which the first part of your tutorial (with code in functions.php) ; then the orders are not automatically completed any more.

    Do you know If I can adjust that to combine this 2 solutions ?

    Thank you very much,

    1. Hi Julie,
      You can try to add this code at the beginning of the file header.php from the custom script:

      $order->update_status( 'completed' );

      It should work.

  59. Hi Nicola and thanks for your expertise 🙂

    I’ve tested with your plugin WC Custom Thank You and your code in header but the plugin makes an error with my theme which manage listings.

    Well, I have add all files in my child theme with your good tutorial.
    With this method I can custom my thank you page and it’s work perfectly with my theme.

    As you said to me, I’ve add code in header.php and now I’ve this :

    Code removed by Nicola

    Unfortunately it doesn’t work with the script for “Automatically Complete Orders” :

    Can you say me If I make a mistake ?

    Thank you very much,
    have a good day

    1. Hi Julie,
      I hope you don’t mind if I removed the code from your comment and delete the duplicates.

      Please try with this script:

      Remove the other one I told you to add before.

      1. Hi Nicola,
        thank you very much and sorry for my duplicate post… I tried every time to put the code with various methods but unsuccessfully…. :S

        I’ve remove the first code you give to me in header.php
        I’ve replace my script in functions.php and replace with your version…

        Unfortunately it doesn’t work…
        Custom Thank You page is OK ! 🙂
        but my order was no longer autocompleted… :”(

        Thank you very much !

  60. Hey Nicola
    Thank you for showing us how to customize the Woo thank you page. Your instructions are clear and easy to follow It’s redirecting fine to the new page but there is no CCS applied.. any idea why? cheers

    1. Not sure honestly, the script does not have anything to do with CSS. Try to purge your cache and/or switch to a different theme temporarily.

  61. Hi Nicola,

    Amazing tutorial, thank you so much for the wonderful code.
    I’ve followed all your steps & used a child theme with it’s own functions.php file (modified with your code).

    Only issue I’ve run into is that the ‘thank you’ page is unable to load after I process a purchase. Woo-Commerce is receiving the order so I know it’s processing but the thank you page can’t be reached.

    Have you seen this happen before? Or can you point me to what the problem might be?

    1. The error message which appears is;

      ‘Firefox has detected that the server is redirecting the request for this address in a way that will never complete’.

      Could this be an error with one of the loops?

      1. Yes it’s possible, but the only loop is in table.php on line 13. You should troubleshoot from there.

        I’m not sure what could be since the code is working for everyone else. Maybe a conflict with another plugin or with the parent theme.

        1. Thanks Nicola,

          I’m using 2012 child theme & have a woothemes one-page checkout plugin which I think might be messing with the end display and causing the error.
          I’ll let you know how I go.
          Thanks for giving me a starting point 🙂

  62. Hi Nicola,

    I’ve figured out the issue, it has to do with the page number I was entering into the redirect.

    Thank you again so much for this excellent code and tutorial.

    All the best!

    1. Great! I’m glad you found the issue!

      Have a nice day!

  63. I did everything as per your instructions, but when i order i am still getting redirected to the cart page of woocommerce. What might be the problem?
    I use avada theme and latest wordpress.

    The website is working fine. Even order is being processed but no redirection.

    1. Hi Sagar,
      I’m not sure, I should check the website. Make sure that the pages are configured properly.

      If you go to WooCommerce > Settings > Checkout check that the Cart and Checkout pages are configured to use your cart and checkout page, and not the same.

      Same thing to check in WooCommerce > Settings > My Account for the My Account page.

  64. Having some trouble myself. I’m trying to use the simple method listed above.

    I went ahead and pasted the code into the correct folder, but my thank you page is not being redirected. I think I know the route of the issue, and maybe you can offer some advice.

    I am currently redirecting my woocommerce checkout page back to the cart page because my customer flow is Cart > Paypal express. I am using Simple Woocommerce auctions as well. When these auctions finish, it takes the customer to the checkout page, not the cart page for payment. Because of this, they miss the Cart page which is where they are linked to Paypal express.

    When I disable the redirect of my checkout page, the thank you page is successfully redirected to my custom page. Any ideas of what could be causing this?

    I tried changing if ( is_checkout() to if ( is_cart() with no results.

    Best, Phil

    1. Hi Phil,
      It could be that your redirect is fired before the one used in my snippet, so mine is skipped.

      Try to change the priority of yours (or mine, making it run earlier).

  65. HI ,

    I have a problem in paypal, after the checkout it will redirect to paypal, if payment succed than also it will dispay the message ” Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction”

    please help on this issue as soon as possible

    1. Hello Jay,
      Please open a ticket at for that.


  66. Which {PAGE_ID} i have to add in function.php file, i don’t have any idea about {PAGE_ID}, can you tell me about that ?

  67. I have created custom-thankyou folder into mytheme->woocommerce folder and uploaded all four files into it. But want to know about the page id which i have to add in function.php ?

    1. Hello,
      In the code, replace {PAGE_ID} with the page ID of your custom Thank You page. To find the page ID read this tutorial:


  68. Thank you for the code, Nicola. I tried the snippet in my functions.php and it worked great. After checkout, the visitor moved over to the thank you page of my choice.


    I deal with digital downloads that need to be immediately available to the user after payment. I found that the script was keeping the WC Order as pending and I had to manually push the order to complete. Do you have a workaround for that?

  69. Thanks for this great tutorial. I’m making use of the plugin and its been great however on the order success page, I noticed that the order details are replicated twice. I’m using optimizepress template.

    1. HI Godswill,
      Can you try with a different theme please?

  70. Hi Nicola. Very useful plugin – thank you! And thank you for carrying on checking these comments!

    How would I adapt it if I wanted to give one thank you message if the customer paid by PayPal (so immediately cleared) and another if paying by BACS (so a delay until payment is confirmed)?

    I can’t be the only one to need this 🙂

    1. Hi Colin,
      Thanks for reading and for your comment!

      So, you can find here how to get the payment method on an order. By checking that, you can change the content of your custom thank you page.

      1. Thank you Nicola for the pointer! It all became clear once a realise an payment method ID (is that a number?) is better described as a payment method slug.

        For anybody else that wants to do this, here is my code:

        switch ($order->payment_method) {
            case "paypal":
              echo ""; _e( "Ready to ship", 'woocommerce' ); echo "";
            case "bacs":
              echo ""; _e( "Ship once funds are received", 'woocommerce' ); echo "";
              echo ""; _e( "We'll get back to you!", 'woocommerce' ); echo "";

        This would make a really good plugin (hint, Nicola!) so that an individual thank you text for every type of payment method could be input on each admin payment gateway setup page rather than hard coding it.

        1. Sorry Nicola – it didn’t accept my php code even though I put it within backticks. The important part is that it is php:

          switch (£order->payment_method)
          (change the pound sign for a dollar!)

          And there were just html paragraph markups inside the echo statements.

        2. Hi Colin,
          Thanks for your code! I edited the comment formatting it 🙂

  71. Hi Nicola,
    Ty for thisvery good tutorial.
    I have a little problem. On order table (where we have the products from order) we have Shipping and Payment Method.
    I want to translate this 2 words but i didnt found it in your files.
    Can you help me please.

    1. Hi Catalin,
      Can you show me a screenshot of the part that you want to translate?

  72. Hi, I was exactly looking for the same but .. redirecting to infinite loop. Just testing direct bank transfer and redirecting to buyer thank you page. but this code is not working .

  73. Hi Nicola Mustone, Can you help on this?

    I was exactly looking for the same but .. redirecting to infinite loop. Just testing direct bank transfer and redirecting to buyer thank you page. but this code is not working .

    1. Hi Rahul,
      Make sure that the WooCommerce pages are different. Each of them should be on their own, and configured. You can check that at the bottom of WooCommerce > System Status Report.

  74. please describe me in details. i am not getting you properly..

    1. Check this document:

      Make sure that the pages in your Settings are not used twice/

  75. Hi Nicola,

    Is it possible to change functions.php so I can use the the order info straight away on my Thank You page without having to print it inside: header.php, table.php and customer-details.php ?

    For example I just want to use billing_email ?> to show the “Billing Email” on my Thank You page using the WordPress text editor, without using external files (header.php…)

    Thanks a lot!

    1. Hi Leo,
      Yes it’s possible.

      Instead of including the files you can print directly the code there. Just replace the wc_get_template codes with the HTML/PHP you want to print.

  76. Hello Nicola,

    I have downloaded and installed your plugin! Works (almost) great, thanks. In the checkoutpage my own page displays well. Unfortunatly the Core WordPress page displays at the bottom of my own page. How can we fix this? Note: I’m using your plugin!

  77. Nicola,

    I have all this code imported into my project, with my page IDs and everything. However, when I complete the order via PayPal and I’m re-directed back to my site (which should re-direct to the custom thank you page), I get the Chrome error ERR_TOO_MANY_REDIRECTS. Checked my code for any faults and updated a few things I missed, but I still get the same issue. Help would be appreciated.


  78. Thank you for your plugin and the Documentation 🙂

    But i have a small problem.

    Order Details page with contains all customer information including Email and telephone number. Normally that details will be shown, only that particulate customer logged in. but in her that details are displayed without customer login. (anyone can view the details )

    Sample Link ––-Alcohol-and-Booze.png

    Can you help me with this please


  79. Hello, I so appreciate your creating this solution.

    I was wondering if this will working the wordpress 4.5.3 and woocommerce 2.6.2?

    thanks again,


    1. Hi Chris,
      A couple days ago I tested the plugin I created for this:

      It works with WP 4.5.3 and WooCommerce 2.6.2.

  80. Hi Nicola,

    Few days ago I found a snippet on “Woocommerce Custom Redirect Based on Item Purchased” at:

    Now this snippet page is gone and I get this:
    “Whoops! This tutorial has moved.
    You may find it on the site of Nicola Mustone at or another source.”

    I looked around your site but couldn’t find this snippet.

    Can you help please?

    Thanks 🙂


    1. Hi Tom,
      The code on that article is this one:

      Add it in the functions.php file in your theme. On line 7 you can find the product ID to change with your product ID and on line 9 you can write the URL of the page where you want people to be redirected.

      1. Thank you!!!!!!!

      2. Question:
        I use this snippet to redirect to custom url after the purchase of product ID 23.
        If a customer checks out few products in the same transaction while only one of them is ID 23 – will it still redirect to the custom url?

        1. Tom, it should. It loops through the products purchased and if there’s one with ID 23 it will redirect.

      3. Nichola,

        If I want more than 1 product to redirect to that url, do I –
        [1] Add additional product IDs with comma, like:
        if ( $item[‘product_id’] == 70,89 )

        [2] Add another if ( $item[‘product_id’] == 89 ), like:

        function wcs_redirect_product_based ( $order_id ){
        $order = wc_get_order( $order_id );

        foreach( $order->get_items() as $item ) {
        $_product = wc_get_product( $item['product_id'] );
        // Add whatever product id you want below here
        if ( $item['product_id'] == 70 )
        if ( $item['product_id'] == 89 ) {
        // change below to the URL that you want to send your customer to

        add_action( ‘woocommerce_thankyou’, ‘wcs_redirect_product_based’ );

        1. You would do:

          if ( $item['product_id'] == 70 || $item['product_id'] == 89 ) {
  81. Thank you Nicola!

  82. Hi Nicola,

    How to add to this snippet a another product ID with different redirect url?

    1. Hi Tom,
      You can do:

      if  ( $item['product_id'] === 1 ) {
        wp_redirect( '' );
      } elseif ( $item['product_id'] === 2 ) {
        wp_redirect( '' );
  83. Thanks.

    And for a third one, should I just add another:

    elseif ( $item[‘product_id’] === 3 ) {
    wp_redirect( ‘’ );

    1. Yes, exactly.

      I usually tend to use the elseif only if there are 2/3 different conditions. If there are more, you should consider a switch.

  84. Thanks Nicola.
    Here is the complete snippet using switch/case (as I guess it with your help & my poor php knowledge).
    Please let me know if it’s correct:

    function wcs_redirect_product_based ( $order_id ){
    $order = wc_get_order( $order_id );

    foreach( $order->get_items() as $item ) {
    $_product = wc_get_product( $item['product_id'] );
    switch ( $item['product_id']) {

    // change below to the produst id & URL that you want to send your customer to
    case 70:
    case 89:
    wp_redirect(‘’); break;
    case 2:
    wp_redirect( ‘’ ); break;
    case 3:
    wp_redirect( ‘’ ); break;
    wp_redirect( ‘’ ); break;
    add_action( ‘woocommerce_thankyou’, ‘wcs_redirect_product_based’ );

    Here is the snippet I currently have for general redirect after purchase to a thankyou page:

    add_action( ‘template_redirect’, ‘wc_custom_redirect_after_purchase’ );
    function wc_custom_redirect_after_purchase() {
    global $wp;

    if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
    wp_redirect( '' );


    My Question:
    Since I added the default line in the switch/case snippet, should I
    (a) Remove the general redirect after purchase snippet I currently have?
    (b) Keep the general redirect snippet and remove the default line from the switch/case snippet?



  85. I may have missed it in the comments, and if so, I apologize.

    I love this code… customized Thank You page without having to mess with the WC templates.

    I would like to do the same thing for a custom My Account page. I can populate all the data, but my question is about the redirect. Your redirect has some specific conditional logic tied to the Checkout process. Not as familiar with all of the various WC functions myself.

    What would that conditional look like to redirect someone trying to access the “My Account” page in order to serve my custom My Account page?

    I know I can copy the template page over to my child theme, but it seems like every time I do this, the next update to WC requires I have to edit that template, even if its just to change the version #. Its a hassle!

    Thanks in advance.

    1. Hi Ed,

      This is off the subject of this thread, but as far as I know If you want to display Woocommerce My Account, you have to place their shortcode in a page you assign for this.
      Woocommerce shortcode for My Account will display their template on that page.
      Redirecting to another page without this shortcode will not display Woocommerce my Account.

      The custom redirect to a thankyou page after purchase is different, as the customer already finished the process through Woocommerce and is now redirected to a simple page that doesn’t need to contain any of Woocommerce shorcodes or templates.

      By the way, I have a customized Woocommerce My Account templates and I suffered the same headache when they changed their templates few times in recent updates.

      The last time they changed their templates, I decided to keep my child themes customized templates with the older version as it works fine for me.

      Just test your My Account and all it’s internal links to see if everything still works the same with the older template version. Maybe you can skip updating your custom templates this time.

  86. Hi Nicola,

    I checked the link you suggested me about the switch, and put together the complete snippet using switch.
    Please let me know if it’s correct:

    function wcs_redirect_product_based ( $order_id ){
    $order = wc_get_order( $order_id );
    foreach( $order->get_items() as $item ) {
    $_product = wc_get_product( $item[‘product_id’] );
    switch ( $item[‘product_id’]) {
    // change below to the product id & URL that you want to send your customer to
    case 70:
    case 89:
    wp_redirect(‘’); break;
    case 2:
    wp_redirect( ‘’ ); break;
    case 3:
    wp_redirect( ‘’ ); break;
    wp_redirect( ‘’ ); break;
    add_action( ‘woocommerce_thankyou’, ‘wcs_redirect_product_based’ );

    I currently have the following general redirect after purchase snippet:

    add_action( ‘template_redirect’, ‘wc_custom_redirect_after_purchase’ );
    function wc_custom_redirect_after_purchase() {
    global $wp;
    if ( is_checkout() && ! empty( $wp->query_vars[‘order-received’] ) ) {
    wp_redirect( ‘’ );

    My Question:
    Since I added the default line in the switch snippet, should I
    (a) Remove the general redirect after purchase snippet I currently have?
    (b) Keep the general redirect snippet and remove the default line from the switch snippet?



    1. Hi Tom,
      The code looks good to me, but please be aware that I didn’t test it on a real website so I don’t know if there are syntax errors or something similar. By reading it it seems to be good.

      To reply to your questions:

      a) Yes, remove it
      b) No, just remove the general redirect.

  87. Nice snippet – have used this a few times and got lazy enough to create a sublime snippet! Life saver!

  88. Thanks so much for both this guide and the plugin!

    1. You’re welcome Diego!

  89. Hi! Custom thank you message for each payment method ?

    there is only the hook does not work (


    add_action (‘woocommerce_thankyou’, ‘myfunction’);
    function myfunction($order_id) {
    $order = new WC_Order($order_id);
    $payment_method = get_post_meta( $order->id, ‘_payment_method’, true );
    switch ($payment_method) {
    case ‘bacs’:
    // do this
    case ‘paypal’:
    // do that


  90. Hi Nicola.
    Works really good 🙂
    Is there a way to do the redirect out of an iframe?
    thank you ever so much!

    1. Hi Guy,
      I’m sorry but I don’t really know this.

  91. Hi i’ve used this custom thank you page but i’m not getting any value on thanks you page i’ve added currect page id and following all instructions plz suggest me


    1. Hello Mukesh,
      I’m sorry but I’m not able to help with more info.

      Try with the plugin instead:

  92. Hello,

    Thank you for the awesome tutorial, i’m trying to Google Adwords Conversion Tag to the thank you page, i’ve used the code in this tutorial and it working but i’m having a problem with wordpress escaping the > character thus rendering my code useless.

    so this:
    /* ]]> /
    becomes this:
    ]]> */

    i tried removing this code : “$content = str_replace(‘]]>’, ‘]]>’, $content);” from :

    and still the “>” character is being escaped.

    I appreciate your help, thank you.

    1. Hello Nabil,
      Try to add your AdWords code in the template header.php from this tutorial, at the beginning of the file.

      Don’t change any file in wp-includes/, for any reason.

  93. hello nicola,
    its a very helpful plugin.its works great.
    i have one issue after failed transaction my cart became empty.
    can u help …

    1. Hi,
      I’m not sure that is an issue. Did you try if it happens also without any customization on your site?

  94. hi dear,

    i want to change the proceed to checkout button with proceed checkout without login. When click on view cart this button below show this

    1. Hi Sid,
      You can override the template proceed-to-checkout-button.php in /cart and change the button text on line 27.

      You can learn how to override templates here:

  95. Hi,

    Good read!! I’m newbie with wp, and I faced some problems here.

    I used storefront’s child theme, should edit function.php and add your script on main storefront theme or storefront’s child theme? after edited and add your script, the site won’t access. I’ve tried to edit/add within both themes

    any idea? thank you

    1. You should edit the file in the child theme. Do you see any error message? What do you mean exactly with not accessible?

  96. Thank you very much for this good workaround.
    You made my day. 🙂
    Greetings from Holland.

    1. You’re welcome! 😉

  97. Nicola,

    This is a fantastic post, many thanks. I’m new to Woocommerce, am a total beginner with php, and am just trying to set this up in a child theme right now. It’s real daunting from a newbie’s perspective, but no doubt this post will make it easy for me.

    Kind regards,


    1. Hey Russ! Thanks, I’m glad you like it!

      Yeah, setting up a child theme is not that hard after all. Just make sure to follow the WP Codex and you will be good 😉

      1. HI Nicola,

        I couldn’t get it working (and checked about 5 times). Payment is made, I go to the receipt page, but it’s not the custom page.

        I have Themes/Divi-child/functions.php (where I add the code for that file). There’s also styles.css in that sub-dir.

        Then under Divi-child, I have ‘woocommerce’ (so it’s ‘Themes/Divi-child/woocommerce’ then the 4 other files files.

        I’ve changed the page ID to the correct page a total of 2 times.

        Is there anything else I’ve missed?

        Many thanks, Nicola.


        1. Hello Russ,
          The files from this article must go in a folder named custom-thankyou inside the folder woocommerce in your theme.

          Are you doing that? From your comment it seems that you are moving the files directly into the folder woocommerce.

  98. Hi Nicola,

    Sorry, yes; the 4 files are in: /wp/wp-content/themes/divi-child/woocommerce/custom-thankyou
    The functions.php is in: /wp/wp-content/themes/divi-child

      1. Thanks, Nicola. I’ve installed the theme but I’m at a loss as to how to configure it…I’m clearly missing something.

        Let me explain further, in a little more detail, if I may…

        I originally set this up in the Divi theme last week and it worked fine.

        Then Divi updated and I read about making the customisations in a child theme so that they wouldn’t get overwritten when Divi updates. I created this and called the subdir ‘Divi-child’. I then recreated the files in the child theme directory.

        I tested it and it didn’t work. I then started this thread (above).

        What I’m failing to see (the obvious, no doubt), is how, after the Paypal purchase, the parent theme redirects to the Divi-child theme and picks up the custom thank you (that you’ve so kindly created here).

        It stands to reason that if I place the functions.php file in the Divi-Child folder, then it can’t do the same job as if I placed it in the ‘same place’ in the main ‘Divi’ theme folder. What in there (the php) will call the functions.php in the child theme folder?

        That’s where I’m at and, though it’s probably a simple answer, I’m baffled at the next step. I’m looking in WordPress/your plugin for some form of config file to edit, but can’t see how to do it.

        Apologies for taking up so much of your time.

        Kind regards,


        1. Hey Russ,
          It’s the other way around.

          WordPress first loads your child theme. From there, it runs its functions.php file.

          WordPress knows that it’s a child theme, so after that file, it runs the parent’s functions.php file.

          Anyway, to configure the plugin go to WooCommerce > Settings > Checkout and at the bottom find the Thank You page configuration dropdown. Choose the page you want to use as custom Thank you page.

          I just tested it with the latest versions of WordPress and WooCommerce and fixed a couple things in it. Make sure to update it from your Dashboard as soon as the update is visible on your end.

  99. I see, thanks for clarifying how that works. I did what you said and that worked perfectly, Nicola. Thank you SOOO much! I really appreciate that and your help along the way.

    Nicola, do you have a Paypal button where I can buy you a cup of coffee or 2 for this?

    Many thanks again,


    1. Thanks Russ 🙂 Don’t worry about it, if you wanna help, make sure to follow me on Twitch at

      I stream about coding sometimes, a follow would be helpful 😀

  100. Hi Nicola,
    Great job on the tutorial!
    I use the plugin that you created for each products to have their own thank you page.
    On the site I am designing i need 3 different thank you pages:
    – one for bookings
    – one for products
    – one for booking request
    on the function.php how can I redirect to 3 different thank you page IDs?

         * Replace {PAGE_ID} with the ID of your page
        $redirect  = get_permalink( 1416 );
        $redirect .= get_option( 'permalink_structure' ) === '' ? '&' : '?';
        $redirect .= 'order=' . $order_id . '&key=' . $order_key;
        $redirect2  = get_permalink( 1417 );
        $redirect2 .= get_option( 'permalink_structure' ) === '' ? '&' : '?';
        $redirect2 .= 'order=' . $order_id . '&key=' . $order_key;
        $redirect3  = get_permalink( 1418 );
        $redirect3 .= get_option( 'permalink_structure' ) === '' ? '&' : '?';
        $redirect3 .= 'order=' . $order_id . '&key=' . $order_key;
        wp_redirect( $redirect );

    Thank you for your help.


    1. Hi Johann,
      You can do that by checking the product ID or type, depends on your setup.

      You can get those data with $order->get_items() and then cycle through all the items to check what’s in the order and define what redirect to use.

  101. Hi Nicola,
    thanks for this informative post.

    How can I preview the failed order template (“failed.php”)?
    I’m having trouble thinking of a scenario where the order would fail (and hope there is a way I wouldn’t have to…)


    1. Hey Yanay,
      You get that template when the order status is Failed. That happens with invalid payment methods, or insufficient funds, usually.

  102. Hello,

    Thank you for the code.
    When I put the function code in the functions.php file of the theme template, my site isn’t available anymore. When I delete the code in functions.php, the site is available.

    I’ve changed {PAGE ID} to my page id of the thank you page

    1. Hi Pim,
      I need more info to give you an answer. Most probably you are adding it in the wrong position or there’s something wrong.

      Also, try to use the plugin instead:

  103. I have issue on custom thank you page. after succesful order page redirect to custom thanks page. I called a API on ‘woocomerce_thankyou’ hook. Its worked fine before install the your plugin. after installed this plugin the ‘woocomerce_thankyou’ hook not triggered. I want to send order details to some API after successful payment.

    Thanks in advance

  104. Hi Nicola.

    Thank you so much for giving alot of your time and effort.

    Can you kindly let me know the coding required to have multiple thank you pages – one for each product. I am looking for a redirect immediately after credit card (other other) payment ….a redirect to a virtual product page. Each of these unique ‘landing’ pages has a different version of the webpage virtual product (not downloadable – just a simple one webpage game)…each in a different lanquage.
    I hope you are able to provide me code for creating a seperate landing destination page for each seperate product.

    Thank you so much !!!!

  105. Hi Nicola.
    Thank you so much for sharing the tips. But, how about if we just copy the ‘thankyou.php’ inside the woocommerce templates, put it in our child-theme directory ” /your-child-theme/woocommerce/checkout/” and edit it, so we don’t need all those new created files?

    1. You are right.
      First commend line in thankyou.php says it all

      This template can be overridden by copying it to yourtheme/woocommerce/checkout/thankyou.php.

  106. Thank you a lot! WOnderful solution. YOu made my day.

    1. You’re welcome Alex!

  107. Hi. I have installed and activated your Plugin, selected the custom thank you page. However, once order is complete and the merchant redirects to the page, there is no content on the page. The entire page is blank.

    Would you be able to assist. I am happy to pay for your services.

    Kind Regards

  108. Hi Nicola,
    I came across your post and think it might help to solve an odd problem occurring on my site. I have 2 plugins, one does sales tax calculations and the other handles gift cards, that seem to toggle the displaying of the discount amount on the thank you page depending if one is enabled/disabled. Both developers are pointing the finger at the other leaving me to figure out an alternative solution.

    What’s really odd is that the amount charged to their credit card is less than what shows up on the thank you page (it correctly reflects the discount), and they get an email confirmation that DOES show the correct discount and order total.

    All I want is to show a thank you page with all the correct amounts, and I was wondering if I can control this by using either your plugin, or the template overrides.

    Thanks for your time and consideration,
    -Ben M.

    1. Hi Ben,
      I’m sorry but I don’t think that this post will solve your problem.

      Even overriding the templates or using a custom thank you page you will show the values from WooCommerce. If those are wrong for some reason they will be wrong also on a custom template or page.

  109. Hi Nicola! Thank you very much for making this for the community free of charge 🙂

    However I am not able to see “Bank details” using your plugin… without your plugin it shows them okay. Is there something that can be done? Thank you!

    1. Hi Daniel,
      I know about that, it’s a bug in the plugin that I still didn’t fix.

      1. is there any solution?

  110. Hi Nicola,

    thanks for the grat instruction!

    But would it be possible to just hide for exaple the “billing_phone” from the order recieved page?

    Thanks in advance!
    Kind regards,

  111. Hi.

    is it possible to use different thank you pages depending on the gateway used for payment?

    In Brazil we have a very common payment method similar to a bank slip, so you still need this person to pay it in the bank so that you can consider the process finished. I’m trying to send those people (which use a gateway exclusive for that) to another thank you page.



    1. Hello Diego,
      It is definitely possible, but this needs further customization. The tutorial does not support this at the moment.

      1. After a few tries, I made it work with 2 different pages.

        Thank you very much for this tutorial, I wouldn’t have achieved it without this page.



        1. You’re welcome Diego!

  112. Hi,
    I am trying to use this code. but unfortunately getting blank page and error log it shows error which is not relevant to this code. this happens when i paste following to functions.php

    add_filter( ‘the_content’, ‘wc_custom_thankyou’ );
    function wc_custom_thankyou( $content ) {
    * Replace {PAGE_ID} with the ID of your page
    // Check if is the correct page
    if ( ! is_page(1119) ) {
    return $content;

    // check if the order ID exists
    if ( ! isset( $_GET['key'] ) || ! isset( $_GET['order'] ) ) {
    return $content;

    $order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $_GET['order'] ) );
    $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
    $order = wc_get_order( $order_id );

    if ( $order->id != $order_id || $order->order_key != $order_key ) {
    return $content;

    // ob_start();

    // Check that the order is valid
    if ( ! $order ) {
    // The order can't be returned by WooCommerce - Just say thank you
    ?><p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p><?php
    } else {
    if ( $order->has_status( 'failed' ) ) {
    // Order failed - Print error messages and ask to pay again

    * @hooked wc_custom_thankyou_failed - 10
    do_action( 'wc_custom_thankyou_failed', $order );
    } else {
    // The order is successfull - print the complete order review

    * @hooked wc_custom_thankyou_header - 10
    * @hooked wc_custom_thankyou_table - 20
    * @hooked wc_custom_thankyou_customer_details - 30
    do_action( 'wc_custom_thankyou_successful', $order );

    $content .= ob_get_contents();

    // ob_end_clean();

    return $content;


    Please advise.

  113. Hi, I have followed your directions exactly since I know nothing about php. As soon as I add the last two codes on the functions.php I get an internal server error 500. If I just leave the first part of the code it works fine… Can you please help me…
    Thank you

    1. Hi Maria,
      Can you please try to use the plugin instead?

  114. Hi,

    I’m trying to add a button below the table that would replace the download link in the product detail table.
    Found the function, but it doesn’t work. Any clue?



  115. I am Using HDFC (india) payment gateway plugin which has its own redirection code after payment success/failure, taking user to Checkout page for showing order summary. How to override this redirection with your custom template? I have copied all your files in respective child themes folder.

  116. works in woocommerce 3?

  117. Hi, great tut, I have used it on Woocommerce 3.2 but it only displays the blank page with no information in it whatsoever, so it is just redirecting the cart page (I have cart & checkout on same cart page) Any tips welcome, Many Thanks

  118. Hi, great tut, I have used it on Woocommerce 3.2 but it only displays the blank page with no information in it whatsoever, so it is just redirecting the cart page, any tips welcome, Many Thanks

  119. Hi, does anyone know where the settings are for this plugin once installed?

    1. This code does not create any settings, it’s just a snippet. If you are using the plugin version instead the settings are in WooCommerce > Settings > Checkout.

  120. @Nicola, is there any way to actually show a sequential order number (in the plugin) instead of a post ID?


  121. Hey Nicola,
    Thank you so much for sharing the tips.
    I use PolyLang.. you see what will be my question.. as Nicolas about WPML.
    If you can give all the code than I must add your php file… I’m not an expert 🙂
    Thanks a lot Nicola !

    1. Hi Rémi,
      I’m not sure about Polylang to be honest, I never used it. Maybe if you contact their support they can help?

  122. This is awesome. Thanks… I don’t see anything that indicates how to include product thumbnail image. Basically, I’d like to repeat the “Review your Order” table, without the “remove product” and “Quantity” columns. But, have the product thumbnail included.

    Any thoughts?

  123. 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?

    1. I meant the thank you page is blank… I added the .php temlates to the woocommerce folder in a child theme as well.

      1. Nevermind, I got it to work! Thank you so much for posting this!

        1. How did you get it to work?
          I get a blank page as well with the latest Woo and latest WP.

          All files in child theme.

        2. Bjornen, did you try to use the plugin instead?

    2. Nevermind, I got it to work! Thank you so much for posting this!

  124. Hello, i just wanted to know, on the first bit of code you copy into the functions.php, where it says,
    wp_redirect( ‘’ ); , do you change the url to the the url of the thank you page i have created on wordpress ie ‘’or does it do that automatically? I’m new to this. Many Thanks Nathan

  125. Hello!
    I have maybe an easy to solve problem, but i’m not a programmer and i could not handle it myself. How can I set the font size for the field “Thank you. Your order has been received without changing the font from default typography because it is very small.
    Many Thanks

  126. Thanks so much for sharing, this is very interesting.

    1. You’re welcome!

  127. 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?

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

  129. 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?

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


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

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

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

  134. 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?

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

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

  137. krushna chandra Avatar


    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

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

  139. 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:

    Much appreciate any guidance you can give me.


    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:

        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.

Leave a Reply




Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Join 651 other subscribers

About The Author

Hi, I’m Nico! Support Lead at Automattic, championing & WooCommerce. Off-duty, I’m at Elemental Beacon, leading epic D&D adventures. Let’s connect, whether it’s about WordPress or a quest!


Don't Miss a Thing!

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Join 651 other subscribers

Continue Reading

%d bloggers like this: