WooCommerce: Display Product Up-sells @ Thank You Page

One of the most important WooCommerce pages, conversion-wise, is the Thank You page. That’s your chance to offer something special to a user that has just turned into a customer and is therefore more likely to purchase again.

We’ve seen how to include a whole WordPress page inside the Thank You page, how to redirect customers to a different Thank You page URL, how to display a custom social media share box on the Thank You page, but in this article I want to expand a little more on the topic and show a list of purchasable products via a shortcode.

The thing is that the Thank You page “does not exist” inside the WordPress pages, so you can’t just add a shortcode in a page. We must do that via a PHP action hook and the do_shortcode() WordPress function. Enjoy!

PHP Snippet: Display Products @ WooCommerce Thank You Page

/**
 * @snippet       Display Product Shortcode @ WC Thank You
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */

add_action( 'woocommerce_thankyou', 'bbloomer_upsells_thankyou' );

function bbloomer_upsells_thankyou() {
	echo '<h2>Buy Some More?</h2>';
	echo do_shortcode( '[products ids="186177,186179,186181"]' );
}


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

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

2 thoughts on “WooCommerce: Display Product Up-sells @ Thank You Page

  1. Hi Rodolfo,

    How could we add/change the product id’s from within an admin panel? Is this possible?

    Raj

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

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 *