Change your WooCommerce thank you page title

WooCommerce comes with a few basic pages that you need in order for the plugin to work. One of them is the checkout page. The checkout page is the page where your customers can fill in their details and select a payment method to complete their order. Since WooCommerce 2.1 the page the user is redirected to after the payment is complete is also the checkout page but with a different endpoint. Although the content changes per endpoint, the page title stays the same. So can you change the page title based on endpoints?

What are endpoints

Before WooCommerce version 2.1 these endpoints where separate pages with their own shortcodes. The ‘thank you’ endpoint now, was the [woocommerce_thankyou] shortcode back then. The reason WooCommerce got rid of all these separate pages and shortcodes is because it makes the installation of WooCommerce a lot less prone to user errors. If you forgot or deleted your ‘thank you’ page your customer would get a 404 after they completed the checkout process. As you can imagine, not a good customer experience.

Changing the ‘thank you’ endpoint title

I’m a supporter of the endpoint solution but there’s one thing I don’t like about it. My customers would see ‘Checkout’ as the page title after they completed their payment. This is the page where I want to thank them for their purchase and not confuse them with the feeling they’re still in the checkout process. Luckily it’s quite easy to change the title of the checkout page just for the thank you endpoint. Below snippet can be placed in your theme’s functions.php.

You can replace the “Thank you for your order!” with anything you like.

Personalizing the thank you page title

For one of my shops I wanted to make the checkout process a more personal experience. One of the things I did was personalizing the ‘thank you’ endpoint title. It’s the first thing that customers see when they completed their order so I wanted to greet them by their first name. Below snippet will fetch the first name of the customer that just completed their order and replace the %s with their first name. Code snippet below will result in for example: Thank you, Barry!

You can change the title in whatever you want, as long as you place a %s in it. A small example of a different title:

$title = sprintf( "%s, you are the best!", esc_html( $order->billing_first_name ) );

This will for example result in: John, you are the best!

I hope this helped you in changing your thank you page title. Are you missing something? Found a problem or improvement? Be sure to let me know by leaving a comment!

Related Posts

Powered By Related Posts for WordPress
Click Here to Learn More About Related Posts for WordPress

37 thoughts on “Change your WooCommerce thank you page title

  1. Hi Barry,

    Great trick, thanks!

    Just a minor heads up: the conditional on line #15 will throw a notice if the $order variable is, for whatever reason, never set (or unset).

  2. Thanks for posting this Barry. I’m trying to get the order-received page to be more dynamic and therefore want to redirect it to a custom page I create. While there is plenty out there for redirecting the thank you page, there isn’t anything on adding order details to the forwarded page. Can you please provide a solution for this? Thank you so much in advance.

  3. Thank for a nice code.

    But on what line in Functions.php should it be copy/paste in?

    I have a lot of stuff there all ready1

  4. daved brosche

    I have built a plugin that lets you create a custom thank you page on a per product basis. Would love to know what you think.

    // Link removed

    The custom thank you page for WoCommerce lets you specify a custom thank you page per product. You can link to other WordPress pages or you can link to a custom URL outside of your website.

  5. Hi Barry,
    I have a question I would like to remove all the customer details, order details, payment info and bank account details etc from the thank you page. It should just say “Thank you for your order, we will get in touch with you.”
    I am very new to WP and don’t know much about PHP, could you help me what I would need to do? I guess I would need to use some remove_action in my child theme’s functions.php, but I don’t know what these would look like.

    Thank you so much,
    Sandra

  6. Is there a way to change the title of this page
    https://puzzlefurniture.com.au/checkout/order-pay/

    Please help.

    Thanks

    • // Change 'Pay for Order' title on checkout payment page
      function abc_title_checkout_pay_page( $title, $id ) {
      if ( is_checkout_pay_page() && get_the_ID() === $id ) {
      $title = "Payment";
      }
      return $title;
      }
      add_filter( 'the_title', 'abc_title_checkout_pay_page', 10, 2 );

  7. Great. What a nice idea for Woocommerce thank you page customization. I tried many other plugin tweaks but not this one.

    I am working on a new Woocommerce website and wanted to try something different this time. Thanks Barry for sharing with us.

  8. Cecily Wiggins

    Would the same apply for the lost password page?

    • You could change the title for the lost password page but you’ll need another check for that. You should be able to use this in your if statement:

      if ( is_wc_endpoint_url( 'lost-password' ) ) {

      Also, be sure to only use variable available on that page. You for example can’t use the first name I used in my blog post because that won’t be set.

      Good luck!

      Kind Regards,

      Barry Kooij

  9. Found this post through some google searching. When you’re checking the for get_the_ID() === $id, what is $id checking against? The endpoint id?

    • Of course I figure it out after I comment. I’ve seen in_the_loop() used to address just filtering the main title(). Can you explain the benefit using your method over in_the_loop()? Thanks

      • I believe you can be in_the_loop() but not filtering the title of the page you want to change. In most cases this won’t happen afaik so both ways should generally work.

  10. Hi Barry,

    Someone on our team used your snippet and all went well until recently when our hosting plan kicked out this error:

    PHP Fatal error: Call to undefined function is_order_received_page() in /our-website/functions.php on line 1038

    The line in question is this one:
    if ( is_order_received_page() && get_the_ID() === $id ) {

    We have *not yet* updated to Woocommerce 2.4.x because of other theme-related issues which we’re working on. Don’t know if that would play a role in getting the fatal error.

    Can you please advise? Thanks much. I realize you’re getting asked for free work when you could be raking it in with your plugins 🙂

    • Hey,

      Well, the first thing I would suggest is to update WooCommerce. Check if your code works on the latest WooCommerce on a separate install to rule that one out.
      Also, if you’re theme or any plugin uses the the_title filter in a funky way, this might cause the fatal error. WooCommerce might not be loaded at the moment that filtered is triggered by something resulting in this fatal error. You could try this code:


      if ( function_exists( 'is_order_received_page' ) && is_order_received_page() && get_the_ID() === $id ) {

      }

      Good luck and thanks for you comment!

      Kind Regards,

      Barry Kooij

  11. Hi
    Can you reply full order received page what function? Pls reply

  12. Hey Barry,

    Nice code!

    I would like to know how to make “%s, you are the best!” translatable with WPML.

    Can you help me?

    Thanks a lot…

    Carlos A.

  13. Nice post about WooCommerce. I would like to share one recently launched Woo-commerce Plugins named WC Checkout Fields Editor. It has features as,
    ~ Supports 11 custom fields
    ~ Edit existing fields(Billing/Shipping) support
    ~ Remove fields & Change display field order
    ~ Product specific field visibility
    ~ Category specific field visibility
    ~ File upload custom field in additional settings
    ~ Display in Order Details page and Email
    ~ Cart total specific field visibility
    ~ User friendly admin panel
    ~ Restore to Default fields
    ~ Translation Ready

  14. Thank you 🙂 Worked perfectly!

  15. Hi Barry,

    Is there a way I can preview thank you page without making a purchase? For development purpose.

    Thanks

  16. Hi Barry

    I use wBounce for exit popup, but I can’t exclude /checkout/order-received/ page. No reason to show exit popup when client just placed real order!

    As I understand order-received is endpoint, not WP page, so I can’t use Pages admin to exclude wBounce action.

    Do you know how I can exclude endpoint?

  17. When I successfully bought a license key digital product how to remove license key field from order receive page

  18. Is there a way to add last name as well?

  19. Hi there,

    Great snippet!
    Is there any way we can add this to a custom thank you page (a different URL to the standard WooCommerce thank you page URL)?

    Cheers

  20. Hi,

    Nice code, but page title should change to “Sorry…..” if payment fails. Can this be done?

    Best.
    GD

  21. Thank you very much

  22. This is still valid after five years. However, I’d suggest to check for the existence of the function is_order_received_page at the beginning and returning the title immediately in in case it does not.
    This is to prevent a fatal error in case you disable Woocommerce.

Leave a Reply

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