Customize the Thank you page in WooCommerce

WooCommerce redirects to the Thank you page after a successfull purchase, but sometimes it’s just not enough for you. What to do in this case? Learn it here

You should always be grateful to your customers and, obviously, thank them after they complete a purchase.

WooCommerce already does this for you. It redirects to the Thank you page after a successfull purchase, but sometimes it’s just not enough for you.

What to do in this case?

 

The simplest thing to do is to redirect customers to another page with your personal thoughts and thank you message.

To do so, open the file functions.php located in wp-content/themes/your-theme-name/ and add this code at the end of the file:

With this code the customer will be redirected to a specific URL after he completes the purchase. But you may feel that still is not enough. It just redirects to a page, but then you miss the order summary table and other important features that WooCommerce provides through the default Thank you page

You can have these information too. Let’s see how to add them in your custom Thank you page.

Build the perfect Thank you page

Create a page in Pages > Add New. Add all the text, images, and stuff you need to thank your customers. Now it’s time to get your hands dirty, a lot dirty.

Create a folder in your theme, if it does not already exist, and name it woocommerce. Inside this folder create a new folder named custom-thankyou. We will use this folder to put all the custom files used for the custom Thank you page. Inside the folder custom-thankyou create four files named

  • failed.php – it will be used to show a message to the customer when his purchase fails.
  • header.php – it will be used to show the order informations to the customer, such as the date, the order ID, etc.
  • table.php – it will be used to show the order summary to the customer, such as the products purchased, the shipping costs, taxes, etc.
  • customer-details.php – it will be used to show the customer details such as the billing and shipping addresses.

Now open the file failed.php and add this code into it:

Then open the file header.php and add this code into it:

And last, but not least, open the file customer-details.php and add this code into it:

All these files are completely customizable. I know, you need a bit of PHP knowledges but it’s something not so hard and you can easily understand where to change the various parts of the code, if you need to. But i splitted them like this just to be sure that you will not need to edit them. You will understand better why later in this tutorial.

Now you need to edit again the file functions.php. Open it with your favourite text editor and find the code we added at the beginning of this tutorial. Replace it with this code:

Be sure to replace {PAGE_ID} with the ID of the page you want to use for your Thank you page. After it, add this other code:

Also here, be sure to replace {PAGE_ID} with the ID of the page you want to use for your Thank you page. This code filters all the pages content and if the page ID actually looped is the same of your custom Thank you page, it will decode the order ID from the URL and fire some actions.

Finally add the last part of the code:

These functions include the custom templates created before when the main wc_custom_thankyou() function fires the actions.

I used intentionally the actions here. As you can see the actions are fired with priority 10, 20 and 30.
This means that between each template you have still nine priorities you can use to add your custom code. All the page content instead (the content written in the page editor in Pages > Edit the page) will appear before anything else.

Well, that’s all. Feel free to comment this tutorial and let me know what you think about it!

Happy thanking!

Data di pubblicazione: 15 May 2023

Articoli

Lascia il tuo primo commento!

Inserisci il tuo commento