WooCommerce: Include Custom WP Page @ Thank You Page

Yes, you can redirect users to a custom thank you page (but please note all your ecommerce Google Analytics tracking will be skipped…). Yes, you can add content to the default thank you page, for example a Twitter “share your purchase” box. And yes, you can even “include” content from another WordPress page!

Basically, in this article, you will see how to write custom content for your WooCommerce Thank You page as a separate WordPress Page, so that you can use WYSIWYG, Gutenberg or a page builder to create something unique, and then ask WooCommerce to “get it” and “include” such page inside the default order-received endpoint.

If you’re not sure what I mean, try taking a look at the two screenshots below. Then, copy the simple snippet and see the result!

Here’s a brand new WordPress page designed with the Gutenberg editor. Page ID is 540, so I will need to remember this for the snippet.
And here’s the final result. The whole page I previously designed as a custom WordPress page, is now “included” in the WooCommerce thank you page. Cool!

PHP Snippet: Include Custom WordPress Page @ WooCommerce Thank You Page

/**
 * @snippet       Include WP Page @ WC Thank You
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.8
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_thankyou', 'bbloomer_custom_thank_you_page', 5 );
 
function bbloomer_custom_thank_you_page() {
	$page_id = 540;
	$page_object = get_post( $page_id );
	echo $page_object->post_content;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Redirect to Custom Thank you Page
    How can you redirect customers to a beautifully looking, custom, thank you page? Thankfully you can add some PHP code to your functions.php or install a simple plugin and define a redirect to a custom WordPress page (as opposed to the default order-received endpoint). This is a great way for you to add specific up-sells, […]
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question is: what changes do we need to make on our WooCommerce website to become compliant? And another important query might be: how does GDPR affect non-European WooCommerce websites? In this […]
  • WooCommerce: How to Add a Custom Checkout Field
    Let’s imagine you want to add a custom checkout field (and not an additional billing or shipping field) on the WooCommerce Checkout page. For example, it might be a customer licence number – this has got nothing to do with billing and nothing to do with shipping. Ideally, this custom field could show above the […]
  • 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 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 […]
  • WooCommerce: Add Tracking Code / Script @ Thank You Page
    How do you add a tracking code to the WooCommerce Thank You Page? Well, with a simple snippet (and no plugin) you can! No matter whether you’re using Google AdWords, Facebook or other forms of marketing – the Thank You Page is such an important section of an ecommerce store and needs some TLC!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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. Follow @rmelogli

12 thoughts on “WooCommerce: Include Custom WP Page @ Thank You Page

  1. Hi Rodolfo,

    Could you explain more about the Ecommerce Analytics? How do they differ from a generic Google Analytics or Facebook Pixel? Is there something that Woocommerce does internally?

    Or are you discussing a hook that developers may use on the thank you page that will no longer be there on a custom thank you? 🙂

    Thanks!
    Mark.

    1. Hey Mark, sure!

      but please note all your ecommerce Google Analytics tracking will be skipped…

      Google Analytics and ecommerce tracking in general is usually hooked to the “woocommerce_thankyou” hook, which fires on the default thank you page. If you direct customers to another page, this hook may not fire, and therefore tracking may not work.

      It’s as simple as that. Of course, you can always include that hook on your custom page, but you need to have dev skills and also make sure it actually works.

      1. Thanks for the clarification! That makes sense.

        I also want to say your code snippets really saved me time by not having to dig into the guts of woocommerce with PHPStorm. I needed a lot of unexpected customisations and thanks to you, our launch was a succcess!

        I can fine tune later for sure. But they saved me considering we had a lot of unexpected tech failures.

  2. Hello. It’s December 2020 and this snippet works great in my custom WordPress theme.

    I wish I could get the page content above the default content ( just below the ‘Order received’ heading ). If there is a way to do that via a functions snippet, I’d love to know.

    Thanks!
    ~Christine

    1. There’s always some sort of workaround you could use. But yes, pity there is no hook in that position alright

  3. Hi there! I would need your help please, I’m a bit lost. After a day of research on the internet I can’t find the trick to make what I’m trying to do and it seems simple to me … I’ve designed a new page using Elementor to replace my traditional Thank You page in woocommerce. But I can’t find the way to display all the “order details”, download links if it’s a eBook etc after a sale on this page that will replace the basic Thank You page. I thought there was a shortcode to do it like for the checkout page, but I’ve found nothing.

    Could you please help me do that? I’m not a fan of adding plugins over plugins on my website and I’ve already designed the new page so … I just need this to complete.

    Thanks ! 🙂

    1. Hi Harvey, 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!

  4. Thanks for your post Rodolfo Melogli. I try custom Thank You, Page, for one of my websites. but it’s not working. maybe I’m missing something. I’m using NameCheap server and my PHP version 7.0

    1. Try again, I’ve revised the snippet since

  5. Hi Rodolfo.
    Thanks for a great article. I am often on your site for a quick woo reference and I really appreciate all you publish.
    I just thought I’d mention, get_page() is deprecated.
    See: https://developer.wordpress.org/reference/functions/get_page/

    1. Awesome, thank you!

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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