Home » WooCommerce: Include Custom WP Page @ Thank You Page

WooCommerce: Include Custom WP Page @ Thank You Page

by Tutor Aspire

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 3.8
 * @donate $9     https://www.tutoraspire.com
 */

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

You may also like