A client of mine wanted to add some text to the thank you page, the page that customers see after they place an order via the default WooCommerce Checkout page.
In this case scenario, they wanted to add a special coupon discount in order to entice buyers to go back to the website and buy again. Enjoy!
PHP Snippet: Add Content to the WooCommerce Thank You Page
/**
* @snippet WooCommerce add text to the thank you page
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 7
*/
add_action( 'woocommerce_thankyou', 'bbloomer_add_content_thankyou' );
function bbloomer_add_content_thankyou() {
echo '<p>Some HTML content!</p>';
}
Mini-Plugin: Business Bloomer WooCommerce Add Content To The Thank You Page
You don’t feel confident with coding? You don’t want to purchase yet another bloated, expensive plugin? Great!
Business Bloomer WooCommerce Add Content To The Thank You Page is a mini WooCommerce plugin, without the usual hassles. One feature. Lifetime license. No annoying subscriptions. 1 plugin file. A few lines of code. No banners. No up-sells. No WP notifications. Use it on as many websites as you like. Lifetime support. 1-page documentation. Super simple settings.
Speaking of which, here’s a screenshot of the settings:
Quick demo:
As you can see the plugin is straight forward. Install it, define the content you want to show via the WP editor, choose the position, and save. Simple – your custom content will now display in the WooCommerce Thank You Page!
Hi, thanks for the info! Could you pleasee write a code to display product image in thank you page? I’m trying for days and all the codes although seems working first but gives server 500 error in elementor when adding the code via shortcode and try to edit the thank you page. Thank in advance!!! 🙂
Could try with https://www.businessbloomer.com/woocommerce-include-custom-wp-page-thank-you-page/ maybe?
Do you know if this will break Cart Flows thank you pages or that it just affects general thank you pages.
Not sure, this looks for a “hook” that is used on the default WooCommerce Thank You page. So, if Cart Flows custom thank you page also includes this same hook, it will show the content – otherwise you need custom work. Makes sense?
Used a link ‘Click to go to My Account’ as below. Excellent – Thanks.
Great!
Hi, once the client purchases the virtual meditaion on my website, on the order received page he should see a link which he can click and access the meditaion immediately. For all payment methods (paypal and razorpay) how do i do that. using woo commerce
Hello Rima, 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!
Could you have it so a message is displayed if a certain product is ordered?
Hey Dan, 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!
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.
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!
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!
Awesome!
How would you add a link within this content? Can you please give me the code for this?
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
Thank you. I would like show the cross sell products on the thankyou page with this coupon. How can we achieve this?
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
Awesome! Still working on 3.2.1
Great 🙂
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.
Awesome 🙂 You should take a look at the add_action syntax and learn more about the “priority”. Hope this helps!
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?
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 🙂
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?
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!
Where do I add these codes?
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!
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.
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
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
Tim, thanks a million for your comment! Try adding a “5” here:
Let me know 🙂
Thank you so much! It worked!
Just need to put the 5 inbetween ‘5’ as well.
best regards
Tim
Awesome to hear that Tim 😀
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!
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
Hi Rodolfo:
Nice site.
Please how could one edit the “order received” page https://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
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!
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!
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
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
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!
Unfortunately the code did not work, I am not sure why? It still just displays the regular Woo message…
Screenshot? 🙂
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
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).
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…
Great 🙂 Make sure you don’t comment out the part that says “do_action (….” that is halfway through that file 🙂
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
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!
Hey, awesome code! Thanks! Is it possible to show the code only when a specific product is purchased?
Thanks!
Mike
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 🙂
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!
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
Thank you for the code, after hours of search I found this so useful code
thanks again
Thanks so much for your feedback Aleksei!
Awesome, Thanks very much, been trying to work out how to do this and you’ve given me the most elegant answer!
Thanks for your feedback Jamie!
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?
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. https://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!
in which file this snippet need to add?
main …… functions.php
Yes Fatima, in the functions.php of your current theme. R
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
Hey Navo, thanks for your feedback. What text are you trying to remove?
hi nice work and perfect. can i add form also instead of text. but i want to add form after order details.
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!
Thank you for this!
How to add content on top of the checkout page? Can it be done in a similar way?
regards
Johannes
Of coarse Johannes – just use this hook instead: add_action( ‘woocommerce_before_checkout_form’, ‘add_content’);
hm, does not work for me…
regards
Johannes
It has to work, as long as you’re using the whole snippet?
I am using it exactly as mentioned but it results white page in wp.
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!
Is it possible to have both this code for the thank you page AND the order email please?
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/
Hey,
Me again…where do I add this?.
You can add them to your template functions.php file 🙂