WooCommerce: Add Content to the Thank You Page

A client of mine wanted to add some text to the thank you page, the page that customers see after they place an order on WooCommerce. In her case, she wanted to add a special offer in order to entice buyers to go back to the website and buy again.

WooCommerce: add text to the thank you page
WooCommerce: add text to the thank you page

PHP Snippet: Add text to the WooCommerce thank you page


/**
 * @snippet       WooCommerce add text to the thank you page
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=382
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.3.4
 */

add_action( 'woocommerce_thankyou', 'bbloomer_add_content_thankyou' );

function bbloomer_add_content_thankyou() {
echo '<h2 class="h2thanks">Get 20% off</h2><p class="pthanks">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase!</p>';
}

PHP Snippet #2: Add text to the WooCommerce thank you page IF payment method is PayPal


/**
 * @snippet       WooCommerce add text to the thank you page for PayPal
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=382
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.3.4
 */

add_action( 'woocommerce_thankyou_paypal', 'bbloomer_add_content_thankyou_paypal' );

function bbloomer_add_content_thankyou_paypal() {
echo '<h2 class="h2thanks">Get 20% off</h2><p class="pthanks">Thank you for making this purchase via PayPal! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next PayPal purchase!</p>';
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

67 thoughts on “WooCommerce: Add Content to the Thank You Page

  1. How can I add custom field after ‘Billing Address’ details?
    Currently I’m using ‘woocommerce_order_details_after_order_table’ but I want further down.
    TIA.

    1. Darshan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi Rodolfo,

    Thanks for the great piece of code! just what I was looking for, I don’t have the most up to date version of WC, but can confirm that this work on v3.4.4!

    Keep up the great work!

    1. Awesome!

  3. How would you add a link within this content? Can you please give me the code for this?

    1. Hello Mark, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  4. Thank you. I would like show the cross sell products on the thankyou page with this coupon. How can we achieve this?

    1. Hey Kevin, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  5. Awesome! Still working on 3.2.1

  6. Wow worked perfectly. Putting the number 5 in put it exactly where I wanted it. Without it being in apostrophes ‘5’ btw. Why couldn’t I put the number 1 or 10? No need to answer as that may be lengthy but just curious.

    1. Awesome πŸ™‚ You should take a look at the add_action syntax and learn more about the “priority”. Hope this helps!

  7. Hi, thank for your advice, it works, i just have a problem with a font, that doesnΒ΄t recognize letter in slovak. It show some marks AKO DARοΏ½EK OD NοΏ½S 10% ZοΏ½AVA!
    How can I change that?

    1. Hey Dasken, thanks for your comment! You should take a look at https://stackoverflow.com/questions/12699037/how-to-display-special-characters-in-php, it should help πŸ™‚

  8. hello, thanks for the write-up but hey am trying to rewrite the wordings on my order-received page but I cant seem to find the page

    This is the page i am trying to edit https://i.snag.gy/D6Q3tr.jpg

    Can you help me?

    1. Hey Ifeanyi, thanks so much for your comment. You can “translate” that string by using this: https://businessbloomer.com/translate-single-string-woocommerce-wordpress/. Hope this helps!

  9. Where do I add these codes?

    1. Hey Jack, thanks for your comment! You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/. Hope this helps!

  10. Hi Rodolfo,

    I am having a problem with my woo as right now, the email confirmations and the check out shows the said notes done by a previous developer but I can’t seem to find where they can be modified, edited or removed.

    1. Hey Wendell, thanks for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  11. Hey, thanks for the code! it helps me a lot!
    I just need to know one more thing.
    Right now, the added content is on the bottom of the page, but i need it at the top of the page.
    How can I change that?

    Thanks in advance!
    Tim

    1. Tim, thanks a million for your comment! Try adding a “5” here:

      add_action( 'woocommerce_thankyou', 'bbloomer_add_content_thankyou', 5 );
      

      Let me know πŸ™‚

      1. Thank you so much! It worked!
        Just need to put the 5 inbetween ‘5’ as well.

        best regards

        Tim

        1. Awesome to hear that Tim πŸ˜€

  12. Hey! Thank you so much for this! I added to the code and it works, but it adds it to the BOTTOM of the thank you page, instead of right under the first thank you text as in your screenshots. I’d love to have it at the top like that–is there a reason mine is getting added to the very bottom (below all the order details?) I feel like people won’t see it there. Thanks!

    1. Hey Meg thanks so much for your comment! See this other comment reply and let me know if this works for you too: https://businessbloomer.com/woocommerce-add-text-thank-page/#comment-19210

  13. Hi Rodolfo:

    Nice site.

    Please how could one edit the “order received” page http://prnt.sc/d4za0m

    (I’ll be grateful if you could show step-by-step how you get to the part where you see the code to edit (for non-experts like me!)

    Thank you

    Winston

    1. Hey Winston, thanks so much for your feedback! It seems you just want to change some strings of text… in this case I recommend to do this: https://businessbloomer.com/translate-single-string-woocommerce-wordpress/. Let me know!

  14. Hello Rodolfo,
    could you let me know how to have a certain text on the Thank you page only when chosen payment method is Paypal?
    Thanks!

    1. Hello Nina, thanks so much for your comment πŸ™‚ I held a free class last month that covered this exact functionality: https://businessbloomer.com/customize-woocommerce-thankyou-page-tutorial. Let me know if this helps! ~R

      1. Hello Rodolfo,
        thank you very much but I am very new to coding and my PHP is limited. In your video you have another condition statement when talking about adding text based on payment type, could you let me know what the code would look like w/o another condition? So really just if chosen method is Paypal, echo …

        Thank you so much!
        Nina

        1. No problem Nina! You just need to use the hook “woocommerce_thankyou_paypal”. I revised the blog anyway, and added one more snippet that should help you πŸ™‚ Let me know!

          1. Unfortunately the code did not work, I am not sure why? It still just displays the regular Woo message…

              1. Hi Rodolfo, my site is in German but the text is the German translation of the Woo default text. Screenshot: https://www.dropbox.com/s/3i1z9a10727ndkg/screenshot.JPG?dl=0

                1. Hey Nina, thanks! Is that all the content that you see on the Thank-you page? Weird, as that’s not the normal behavior of such page, you should have the order details and other information πŸ™‚ Unless you only put the first part of the page in your screenshot I believe there is some sort of error or plugin conflict there (my snippet shows a notice under the order details).

                  1. Okay, that makes sense now…I have commented out the order details in the thankyou.php because I don’t want them to show up! I need to add the custom text right below the regular Woo message…

                    1. Great πŸ™‚ Make sure you don’t comment out the part that says “do_action (….” that is halfway through that file πŸ™‚

  15. Hej Rodolfo
    On the woocommerce check out page a standard text shows ‘Thank you. Your order has been received.’ Because my client is using the danish translation of woocommerce, this text is ‘automaticly’ changed into the danish equivelant. Now my client want to have changed the text a little bit, and I am not sure where to do it. I found the original English ‘thank tou’-text in the thankyou.php, but am not sure if I should change text here.
    Thanks for your reply.
    Kind regards
    Ronald

    1. Hey Ronald, thank you for your comment! If you only want to translate 1 or 2 strings, you could try using this snippet: https://businessbloomer.com/translate-single-string-woocommerce-wordpress. Otherwise your plan B would be to override the template, but that’s not a good idea. Let me know!

  16. Hey, awesome code! Thanks! Is it possible to show the code only when a specific product is purchased?

    Thanks!
    Mike

    1. Hello Mike, thanks for your lovely feedback! Yes, you can use https://businessbloomer.com/solved-woocommerce-check-product-id-order/ to detect if a product has been purchased, and then apply the snippet conditionally. Let me know πŸ™‚

      1. Wow, thanks for such a quick info!

        Hmmm…ok, so I understand there is a solution, but have no idea how to implement it πŸ˜‰ Let’s say my product name is TEST and I want to say “Hey, thanks for buying the TEST product. Here is a discount code that you can use to purchase XYZ product”.
        How should the code look like and where do I put it?

        I am basically trying to upsell πŸ™‚
        Also, is there a way to redirect to a custom thank you page based on a purchase of a particular product? So again I would like a client buying the TEST product to be redirected to a Thank you page, where I can show him a discount code.

        Thank you!

        1. Hey Mike, thanks so much for your feedback and comment!

          Yes, this is all possible of course – but unfortunately this is custom development work and I cannot provide this solution on the blog.

          If you would like to get a quote for the fix, feel free to go here to get in touch.

          Thanks for your understanding!

          ~R

  17. Thank you for the code, after hours of search I found this so useful code

    thanks again

    1. Thanks so much for your feedback Aleksei!

  18. Awesome, Thanks very much, been trying to work out how to do this and you’ve given me the most elegant answer!

    1. Thanks for your feedback Jamie!

  19. This is a handy snippet, thanks!

    i was just wondering is there a way to do this as a conditional based on the order total?

    ie if order >= $100 then show that coupon message on the thank you page?

    i did try and do this but cant seem to get extract the order value variable?

    1. Jay, thanks for your message! Of course, you could do something like this. You can append the Order total to the thank you page URL e.g. http://thank.you?total=120. On the thank you page, you can use PHP $_GET to do a conditional check. If $_GET[“total”]>=100 { do something }. Hope this helps!

  20. in which file this snippet need to add?

    main …… functions.php

    1. Yes Fatima, in the functions.php of your current theme. R

  21. i am able to add the new text. but i am still able to see the old default text after that i see my newly added text, is there a way i can replace the previous default text and only see the new one

    1. Hey Navo, thanks for your feedback. What text are you trying to remove?

  22. hi nice work and perfect. can i add form also instead of text. but i want to add form after order details.

    1. Thank you Eshwar! Of course, you can add any HTML via that hook. However, if you need to place such form after order details, I suggest overriding the thankyou.php file. Hope this helps!

  23. Thank you for this!

    How to add content on top of the checkout page? Can it be done in a similar way?

    regards
    Johannes

    1. Of coarse Johannes – just use this hook instead: add_action( ‘woocommerce_before_checkout_form’, ‘add_content’);

      1. hm, does not work for me…

        regards
        Johannes

        1. It has to work, as long as you’re using the whole snippet?

          
          // add text on top of the checkout page
          
          add_action( 'woocommerce_before_checkout_form', 'add_content');
          
          function add_content() {
          echo '<p>some HTML here</p>';
          }
          
          
          1. I am using it exactly as mentioned but it results white page in wp.

            1. Are you using this function together with the other for the thank you page? You can’t have 2 functions with the same name. Hope this does the trick!

          2. Is it possible to have both this code for the thank you page AND the order email please?

            1. Hello Vu πŸ™‚ Of course this is possible. You can add content to the order email, take a look at my article here: https://businessbloomer.com/woocommerce-add-extra-content-order-email/

  24. Hey,

    Me again…where do I add this?.

    1. You can add them to your template functions.php file πŸ™‚

  25. […] client of mine asked me to add some text to the thank you page and the customer order email. In both casea, my client wanted to show an immediate upsell to get […]

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.