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, social media share and other information that could help you convert additional sales. 

The default Thank You page in WooCommerce

PHP Snippet: Redirect to Custom Thank you Page – WooCommerce

/**
 * @snippet       WooCommerce: Redirect to Custom Thank you Page
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */
 
add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
 
function bbloomer_redirectcustom( $order_id ){
    $order = wc_get_order( $order_id );
    $url = 'https://yoursite.com/custom-url';
    if ( ! $order->has_status( 'failed' ) ) {
        wp_safe_redirect( $url );
        exit;
    }
}

“Redirection won’t work for me?”

I was recently working on a client’s website and used the snippet above – nothing was working. I even tried to use a redirection plugin (Simple 301 Redirects), but that didn’t work either.

Here’s what I found out: while editing the WooCommerce Endpoints settings, he left a blank space between “Order” and “Received” (see image below, text is translated badly by Google from Danish to English).

That was it!

Broken Thank You Page and Redirect Won't work either!
Broken Thank You Page and Redirect Won’t work either!

Mini-Plugin: Business Bloomer WooCommerce Redirect To Custom Thank You Page

You don’t feel confident with coding? You don’t want to purchase yet another bloated, expensive plugin? Great!

Business Bloomer WooCommerce Redirect To Custom Thank You Page is a mini WooCommerce plugin, without the usual hassles. One feature. Lifetime license. No annoying subscriptions. 1 plugin file. A few lines of code. No banners. No up-sells. No WP notifications. Use it on as many websites as you like. Lifetime support. 1-page documentation. A super simple settings dashboard.

Screenshot of the settings:

Quick demo:

As you can see the settings are pretty straight forward. Select a WordPress page from the dropdown, and automatically redirect successful orders to that page.. You can even “append” the order key to the URL, and print the order details on the custom page via a shortcode. Simple!

Advanced Plugin Alternative

As many readers would love to code but don’t feel 100% confident with it, I decided to look for a reliable plugin that achieves the same result.

In this case, I recommend the YITH Custom Thank You Page for WooCommerce plugin. On top of picking your custom redirect URL, you can also define a different thank you page by category/product, show/hide default information, enable social sharing, display upsells and much more.

But in case you wish to code, keep reading 🙂

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: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]
  • WooCommerce: Disable Payment Gateway by Country
    You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common requirement for all of those who trade internationally. Here’s a simple snippet you can further customize to achieve your objective. Simply pick the payment gateway “slug” you want to disable/enable […]
  • WooCommerce: Disable Payment Gateway for Specific User Role
    You may want to disable payment gateways depending on the logged in user role. For example, you may want to disable PayPal for user role “subscriber” or enable a specific gateway for user role “customer”. All you need is to paste the following code in your functions.php or to install a super simple plugin. Enjoy!

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

166 thoughts on “WooCommerce: Redirect to Custom Thank you Page

  1. Great! So, I have like 6 to 8 products on my website, I only want 1 of them to go to a page.

    So if I use this how do I only have that one product do that, not all of them?

    1. Hello Richard, 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!

  2. Thank it work in Hungary, without the space character in woo settings.

  3. Hi Rodolfo, is possible to modify snippet that after order it will show native thank you page and after while (one or two seconds) will redirect to defined page?

    1. Hi Vladimir, 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. Hi Rodolfo, I have had much use of your woowisdom in the past. Now I ran into a problem which is a bit off-topic… could you do a blog on this: When a customer decides to make a purchase on the website and clicks through to the payment window (which for example for Paypal is not on my actual website), if he then cancels the payment (maybe because he decided to pay with another method…) the customer is redirected to the home page. Is there a snippet to redirect him straight back to the checkout page?
    Thanks Rodolfo you are the best!

    1. Hi Judith, by default PayPal should go back to the Cart page upon cancel. That’s unless you have no Cart page, in which case it will go to the homepage. From WooCommerce core:

      	public function get_cancel_endpoint() {
      		$cancel_endpoint = wc_get_cart_url();
      		if ( ! $cancel_endpoint ) {
      			$cancel_endpoint = home_url();
      		}
      
      		if ( false === strpos( $cancel_endpoint, '?' ) ) {
      			$cancel_endpoint = trailingslashit( $cancel_endpoint );
      		}
      
      		return $cancel_endpoint;
      	}
      
  5. Hi, can we redirect user to an external website after successful payment?

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

  6. one question
    how do i solve multi redirect
    help

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

  7. Nice snippets here! Clear explanation also 🙂 Keep it up!
    P.S. It’s actually not Danish but Dutch 🙂

    1. Ahahahah lol!

  8. Everything just works fine ,Thank you for providing this much needed information to me .
    Can we have different redirects for different products?
    Please help me out in this.

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

  9. Perfect, thanks!!!!!

    1. Great!

  10. Hi

    Need help from you. I am working for Woocommercce project where My order confirmation page is not redirected to the success page. its redirect to the checkout page only. can you pls tell me how to fix it?

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

  11. Works like a charm! thank you!

    1. Awesome

  12. I’ve using this code for a while but it isn’t working any more.

    1. Gaizka, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  13. Hello,
    I am trying this code on my site but it is not working.
    I am expecting it to work with CartFlows Plugin

    1. Your expectations are too high… this works with default WooCommerce while I’m not sure what happens with third party plugins.

      1. Loved your reply!

        1. I know LOL

  14. Is there a way to can redirect to differents thank You page based on what type of product has been bought?
    F.e. :

    checkout for product A –> Thankyoupage A
    checkout for product B –> Thankyoupage B
    checkout for product C –> Thankyoupage C
    etc etc

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

  15. Hello
    i made a custom thank you page plugin.. but but when the custom than you page is not set then after purchase it should go to default wordpress thank you page. Can you please help me for that?

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

  16. Thanks for share this trick. Now I can Customize my website thank you page. Special thanks for that plugin….

    1. Great!

  17. Hola Rodolfo,
    muy buen ejemplo, pero no me funcionó el código.
    algo pasa con la url de retorno de pago que ni siquiera me lleva a mi sitio, sino que redirecciona al sitio de pago.
    no logro ni siquiera que me lleve a mi página de saludo (thank you).
    hay alguna forma de detectar el problema mediante WordPress?

    gracias,

    1. Hola Patricio, 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!

  18. Hey Rodolfo,

    yet again another really great code snippet that helped me a lot when I added conversion tracking to my woocommerce store.

    Thank you so much for your great posts. You always seem to have the exact answer to my problems when I am at the end of my ideas.

    1. Good to know – thank you!

  19. At the bottom of many of your articles, you ask “Does this snippet (still) work?”

    My question is, do you expect that many of these snippets will fail after a certain amount of time? If so, wouldn’t it be better to use reputable plugins to prevent this?

    I’ve happily used probably 20 of your hooks in my functions.php file, but if 1 of those hooks were to break every month, that would be a pretty big problem.

    Thanks!

    1. Hi Phil, thanks for your email.

      As WooCommerce plugin code always improves, sometimes they change things or deprecate others. This means, same as for third party WooCommerce extensions, also my snippets need to be checked some now and again. There is no “forever” for either plugins or snippets.

      Usually, however, WooCommerce changes things but also it keeps “old” ones working for a certain amount of time. In tech lang, you would say they provide “backwards compatibility” for a little while.

      Hope this helps

  20. Hi, how do redirect user to custom link after UNsuccessful checkout? Just in case something happened with the payment gateway or they cancelled the checkout

    The order/ ticket has been put to pending payment and if they try to pay again it says pls remove from cart.

    If I can redirect them straight to my account -> orders then they can click on PAY button there

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

  21. Hello

    Is it possible to redirect to a specific page depends on product category and payment gateway? For example:
    If payment gateway A and product category A, go to page A
    If payment gateway A and product category B, go to page B
    If payment gateway A and product category C, go to page C

    Thanks~

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

  22. Hi,

    Tested the code but doesn’t work!
    Searching the internet, but no custom solution found.

    My code:

     
    add_action( 'woocommerce_thankyou', 'wkbe_redirectcustom');
      
    function wkbe_redirectcustom( $order_id ){
        $order = wc_get_order( $order_id );
      
        $url = 'https://my-website.be/bedankt-voor-uw-aankoop/';
      
        if ( $order->status != 'failed' ) {
            wp_redirect( $url );
            exit;
        }
    }
    

    I don’t know why this code not work. Is there an update that ‘broke’ the snippet ??

    1. Thanks for that. I’ve revised the snippet now, try the new version and let me know. Thank you

  23. Just wanted to say thanks for putting this video and post together. You just saved me a boatload of time trying to figure this out on my own!

    1. Yay 🙂

  24. You’re a life-safer, thanks!
    I also had a space in one of the endpoints, causing issues. Thanks to you they are gone. I also added the code snippet for the thank you page, works like a charm!

    1. Awesome 🙂

  25. Hi,
    Could you please help in verifying the wc_order_key on order-received page. I need to very key on cancel order and redirect the cutomers to the appropriate page instead of thankyou page.

    1. Hey Sandeep, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  26. Great Script! A few issues to report and questions, if I may.

    I copied and pasted the script and change the redirect url. Here is what I’m experiencing.

    Issue #1:
    When I use the PHP snippet with wp_redirect, nothing happens. No redirection occurs. Also, there are no errors in the error logs, I’m having a very hard time debugging. Suggestions on trying to figure out why it wouldn’t be firing?

    Issue #2:
    When I switch to the Javascript version, the full thank you page loads first, and then it redirects to the other page correctly. So, clients get to see the original thank you page, and then it “disappears” on them. They are very confused by this, and this has created so many support requests that we’ve uninstalled it.

    Current workaround:
    I fixed all of this by using the PHP snippet and changing out wp_redirect for the PHP function

    header()

    so it looks like this now:

    header("Location: ".$url);

    This works fine, but it breaks conversion tracking. The woocommerce_thankyou action we were using for that never gets fired because header() can’t have anything preceeding it.

    Is there a way to redirect this so that our conversion tracking code still works, but the client never sees any part of that page load?

    1. Thanks for that Blue 🙂 Maybe you could customize the default Thank You Page (e.g. https://businessbloomer.com/woocommerce-add-text-thank-page/) and that would solve your problems?

  27. I believe the `woocommerce_get_return_url` hook is a more elegant way to do it. This will redirect instantly without having to let the client do 2 redirects (default redirect) and (js script redirect).

    1. Very good point Rens, thank you for that! You’re right 🙂 However it’s important to know all the tracking such as Google Analytics for ecommerce is in the default thank you page, so loading it and then redirect would be better for tracking purposes. Hope this helps!

  28. First of all, thank you so much for this, its a great code to use, very helpful.

    I have used this code to redirect buyers of a ‘Subscription Product’, to this ‘thank you page’.
    I have set up the ‘Thank you page’ as the registration page to become a Vendor. This way people can become a paid member of the platform before being able to register their shop. It works!

    One problem. When I buy a product as a Buyer, I am also redirected to this page.

    I should really only be redirected to the ‘thank you page’ when buying a subscription product, not when buying a normal product. Is there any way to change this code so that this ‘thank you page’ only shows up when buying from a particular product category?

    Thanks a million!

    1. Hello Sanne, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  29. This snippet works like charm!

  30. Thank you! It works well.

  31. Hello Rodolfo! I hope you can help, what can I do to redirect ONLY falied orders.. since this is a thank you page, what should I change to redirect only failed payments to a TRY AGAIN page?

    1. Hola Alvaro, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  32. Works great still. Thank you so much for this solution!

  33. Thanks a lot ! it worked great for me. I’m from Spain, and i have a cooking site. You are great man !

    1. Muchas gracias Miguel! Good luck 🙂

  34. Thanks Rodolfo for great code.
    I need your help in this caes.
    My site using multi language with polylang, I want to redirect to thank you page of each language. My code is:

    // Redirect custom thank you
    add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
    function bbloomer_redirectcustom( $order_id ){
    
        $order = new WC_Order( $order_id );
    
        if( get_locale() == 'en_US'){
            $url = get_site_url().'/thank-you';        
        }else{
            $url = get_site_url().'/vi/cam-on';
        }
        if ( $order->status != 'failed' ) {
            wp_redirect($url);
            exit;
        }
    }

    But it only redirect to defaulf language (in English).
    Is there any ideas in this case ?
    Thaks so much!

    1. Liêm, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  35. Hello Rodolfo,
    thank you for your great articles, you saved me a lot of headaches 🙂

    I’ve been using this snippet (method 1) succesfully for long time, but since a few weeks it doesn’t seem to work anymore. I’ve tried the snippet 2 too, but it doesn’t work either.

    Has anything changed in woocommerce lately?

    Thanks

    1. Hay Paolo, thanks for your comment!

      No, nothing has changed I’m afraid. Maybe it’s your theme’s fault or a plugin conflict.

      Go to WP Dashboard > WooCommerce > System Status: what errors do you see in red font?

      Also, take a look at this tutorial to see how to troubleshoot: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

      Hope this helps!

      R

  36. Hi Roldolfo,

    Great help your blog!

    I just wanted to know if I have to re-direct the endpoint (order-received) if I want to track the orders in Google Analytics as a goal? I know i can track Ecommerce orders in € in GA, but I have to connect goals with Google Adwords later on.

    Or is there a easier way? Just an url for an payment for example?

    1. Erik, thanks for your comment! I’m not sure I fully understand your question. If you want to track GA Ecommerce, use https://wordpress.org/plugins/woocommerce-google-analytics-integration/ and the standard Thank-you page

  37. hows to make a function redirect user to my-account when creating a new account on my-account, and continue to checkout when creating account upon checkout.

    1. Richard, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  38. Hello,

    I am trying to redirect on a specific page after purchase a specific product. How can i do that? please help

    1. Hey Mofazzul, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

    2. Hi.

      We have this all working but:

      Works just great and very pleased with the look of our thank you pages “Finally”
      The standard thank you page is. well quite rubbish looking!
      We now have a big issue though as we use iDevaffilate as a commission solution for our affiliates.
      They have been missing a lot of the commission and its not being logged at all, I spoke with the developers of iDevaffilate and they came back with this.
      With WooCommerce, make SURE you land on the order-received page provided by WooCommerce (on your site) after payment is made. That is where the tracking pixel call is made from. you have to use the stock/default order-received page. “speak with the developer and see if they have a solution” Because if this page is unable to track commissions, we assume it is also not able to track any advertising links after check out as the chain is broken when they leave the site and return to a custom woo thanks you page.
      The standard woo commerce thank you page picks the tracking back up on return..
      Can you please advise how we can continue using your solution But also track sales and commissions?

  39. Hi!

    I was sincerely hoping that this would work for me, however I have the feeling I can’t get past this: my qTranslate is interfering with the WooCommerce endpoints. I tried everything, went searching for hours on forums and GitHub (but the qTranslate support is almost non-existent).

    If I disable qTranslate everything works fine, but once I enable it, my thank you page is non-existent and shows: You can’t shop while your cart is empty.

    I have no idea what to do – I thought I could redirect it and that would fix the issue sort of, but it is not. I understand that this is maybe not the place for this, but I’ve run out of options – do you maybe have a suggestion (on where to look even)?

    The whole website is build according to qTranslate, I think switching a different multilingual plugin means re-doing hours of work.

    Also for the record – this is my first time building a website – so forgive me for beginners mistakes.

    Thank you a lot in advance.

    1. Hey there 🙂 Thanks for your comment but I’m afraid I can’t help via the comments for custom troubleshooting

  40. Thanks For this. Now I am able to redirect the page. I also want the order number. so how I can get this?

    1. Abhay, thanks for your comment! You could pass the order number in the URL, and then “$_GET” that on the page. Yes, you will need a bit of PHP skills for this 🙂

  41. Hey Roldolfo

    Thanks great code!

    Is there a way to show the order details that normally show in the standard woo thank you page please

    So the table with Id, product, amount, shipping amount, total etc
    And the address.

    Thanks
    Matt

    1. Hey Matt thanks for your comment! Yes, of course there is, but at this stage why not using the default thank you page then? 🙂

      1. I have the same question. The reason we want to do this is because we want the basic order info details with the option to add related products, discount codes etc. on the page below these details (something the default woocommerce page doesn’t have.

        Thanks for the tips, by the way!

        1. The default thank you page lets you add content below the order details, that’s correct. But you can always use a jQuery workaround to move a div above the other and reorganize the page layout (or simple CSS to turn it onto a 2-columns page). I’d prefer this way

  42. i am using this code its working fine but ccavenue payment gatway is not redirecting thankyou page its redirecting to woocommerce my account page. Please can you help me out of it..?

    1. Hey Mounish, sorry but I can’t give support here 🙂 If you remove my snippet, does the gateway redirect to the default Woo thank you page? If yes, this problem is independent from my snippet. Let me know

  43. I have Woo commerce setup in my site with Guest checkout. Set some parameters for checkout page to see without login into woocommerce site. and order it, but after order, it not redirect to Order receive page, but redirect on the login page. do you have any solution for this?

    1. Hey Chris! Unfortunately this might be custom to your particular situation so I can’t help for free here on the blog. Thanks for your understanding, R

  44. Hello Rodolfo,
    Great tutorials! Thank you. but
    I’ getting this error all the time : “Thank you for shopping with us. However, the transaction has been declined.”

    Amount has been successfully transferred but the msg appeared on webpage is … “Thank you for shopping with us. However, the transaction has been declined.
    What is the solution for this?

    Thank you for your help.
    Nilay Deshpande

    1. Hey Nilay, thanks for your comment! If you remove my snippet, you still get the error?

  45. Hi Rodolfo,
    Great tutorials!
    For the thank you page, I have a website where I want 3 different thank you pages depending on the product.
    I downloaded a plug-in that do just that and its great BUT I want the thankyou.php order details at the bottom of my custom page.
    Is it possible or do I have to do it manually?

    Thank you for your help.
    Johann

    1. Hello Johann, thanks for your comment! In order to show order details on your custom pages, you will need to add them via PHP via a custom shortcode or other way. Hope this helps!

      1. Hi Rodolfo,
        Thank you for your reply, it help and I have done it but after watching you video “How to customize the Woo thank you page” I found the right way.
        using the code below it work like a charm:

        add_action( 'woocommerce_thankyou', 'check_order_product_id', 1 );
        function check_order_product_id( $order_id ){
        	$order = new WC_Order( $order_id );
        		$items = $order->get_items();
        		foreach ( $items as $item ) {
        		   $product_id = $item['product_id'];
        
        			  //* single product id
        			  if ( $product_id == 115235 ) {
        				// Content Title line
        				echo '<h2>Hello</h2>';
        				}
        

        But will I be able to put multiple product_ids?

        			  //* single product id
        			  if ( $product_id == (array ( 11, 52, 35  ) {
        				// Content Title line
        				echo '<h2>Hello</h2>';
        				}
        

        I tried this code but doesn’t work, or can I use the category (product_cat) instead of product_id

        Thank you very much for your help.

        1. Yes 🙂 Check the PHP function in_array(), you could check if product_id is inside an array of IDs. Let me know

          1. Hi Rodolfo,
            great idea and it works great, but i will need to update the function each time I add a product?
            Could it possible to do it with category ID (product_cat)?
            Thank you for your insight

            1. Yes, of course. You could check if the product belongs to a category via the PHP function “has_term”, as I explain here: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. It’s a little bit trickier to implement so good luck 🙂

  46. Rodolfo, thanks for this! I’m new to this and my issue is I’m having trouble with the thank you/confirmation page missing when someone purchases on my site. I’ve looked a few places for an answer and see others have the same issue unresolved. Can you offer any advice? Is this page missing for everyone? I was thinking I did something wrong here. Thanks!!! Marjorie

    1. Hey Marjorie, thanks for your comment. WooCommerce gives you a default thank you page, where all details show. If it doesn’t work there is a major problem with your theme or other plugin. Take a look at this video tutorial to learn how to troubleshoot maybe: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/. Let me know!

  47. Hi,
    I want to redirect to checkout page on successful update of cart from cart page??
    Is there any way to do this.

    1. Hey Bilal, thanks for your comment! I’m afraid this is not a great idea in regard to User Experience, as the user didn’t choose to go to checkout. Sorry but I can’t help in this case!

      1. Thanks for your response. Actually my client wants to add complete cart page on a slide and to skip cart step so it will redirect to checkout page directly. That is my first project with woocommerce and i am not very experienced but now job is completed.

        1. Hey Bilal, thanks for your reply 🙂 You can redirect to checkout after add to cart by doing the following:

          1) go to WooCommerce > Settings > Products > Display and disable both options: “Redirect to the cart page after successful addition” & “Enable AJAX add to cart buttons on archives”
          2) then, use this snippet: https://businessbloomer.com/woocommerce-redirect-checkout-add-cart/

          Hope this helps!

  48. 
    add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
     
    function bbloomer_redirectcustom( $order_id ){
        $order = new WC_Order( $order_id );
     
        $url = 'https://....';
     
        if ( $order-&gt;status != 'failed' ) {
            echo "window.location = '" . $url . "'";
        }
    }
    
    

    when i am using this code i got error .
    Please can you help me this

    1. Hey Mounesh, thanks for your comment! Have you tried the other, more efficient snippet? What error do you get?

  49. I cant find how to put it inn the Fuction.php and get it to work i have try all with no luck

    1. Hey Fannar, thanks for your comment! Take a look at this video tutorial, it should help you: https://businessbloomer.com/woocommerce-customization-hangout/

  50. is there any way i can display total cart amount on thank you page ? actually i am trying to redirect to different website which has paypal button on it. redirect is working fine. but i want to display order number and total amount payable on my other websites page where i am redirecting after checkout. My payment gateway is on that another site.

    1. Hey Sachin, thanks for your comment! You could try pass the order number and order total in the URL via query strings:

      $url = 'https://yoursite.com/custom-url?order_total=300&order_number=95';
      

      Let me know!

  51. Hey,

    I am trying to redirect a customer to a different thank you page depending on the product I am selling.

    I do not want every customer to see the same thank you page and I also want to redirect to third party websites using cutom urls.

    Is this possible?

    Thanks

    1. Hey Leon, thanks for your comment! I will actually teach this on my next online class: https://businessbloomer.com/customize-woocommerce-thankyou-page-tutorial. Hope you can make it or register anyway to watch the recordings 🙂

  52. Hello) Custom thank you page, depending on the method of payment ?

    The code below is not working (

    
    add_action ('woocommerce_thankyou', 'myfunction');
    function myfunction($order_id) {
      $order = new WC_Order($order_id);
      $payment_method = get_post_meta( $order->id, '_payment_method', true );
      switch ($payment_method) {
        case 'bacs':
          // do this
          break;
        case 'paypal':
          // do that
    
    
    1. Hey there, thanks for your comment! Sorry but I don’t offer support / customization to free subscribers, hope this is ok. By the way, that snippet is incomplete, it’s missing something at the end – what exactly is not working? Thanks 🙂

  53. Hi Rodolfo,

    Great site and really helpful info re thank you page redirect.
    I’m however trying to redirect from a woocommerce contact form to an existing URL on my site.
    I’d like a user to be redirected to my specific site URL once they have pressed the “Submit” button of the contact form.
    Please see the contact form code currently on the site below.

    Would you possibly have a solution for this?

    Cheers
    Norsky

    1. Hey Norsky, thanks for your comment! I’m afraid WooCommerce does not provide contact form functionality, so it must be a third party plugin/theme. You’ll need to ask their support if URL redirection is allowed 🙂 Sorry for not being able to help!

  54. Thanks for the snippet!
    Is it possible to have a redirect AFTER the default order-received endpoint page?

    So, customer pays -> transaction complete -> the WC default order-received endpoint page -> wait for x seconds -> redirect to a custom page?

    Thanks.

    1. Vuster, thanks a lot for your comment! The wp_redirect function doesn’t allow you to delay the redirect. I would use the PHP “header” function instead, but I cannot provide a fix right now here. Take a look at this snippet from PHP manual – if it works let me know and I’ll update the blog. Cheers 🙂

  55. Hello

    I have tried PHP Snippet 1 but it show 404 page after i have placed order. Then i add the PHP Snippet 2 now there are both these codes in the site and site shows EEROR HTTP 500.

    1. Hello Jimmy, thanks for your feedback! So, a couple of things:

      1) Snippet #1 is the best and fastest solution. Please change “https://yoursite.com/custom-url” with the URL you want to send people to. It must be a page that currently exist in your website 🙂

      2) You cannot have the 2 snippets at the same time. They both declare a function called “bbloomer_redirectcustom” and you cannot declare a function twice in PHP. Please remove one of the 2 snippets 🙂

      Let me know if this helps!

  56. Hy

    I have used both code one by one but it is not directing to Thank you page.

  57. Hi Rodolfo,

    I cannot get either snippet to work on my site. I suspected that another plugin maybe interfering, but I’ve turned suspected ones off during test and still cannot reproduce.

    Besides the space being in the “Received Order” field are there any other known bugs that would stop the script from working?

    If another plugin uses the “woocommerce_thankyou” action, would that negate your snippet?

    Thanks!

    1. Hey Soopah thanks for your comment! I just tested this snippet on Woo 2.5.5 and it works perfectly, so unless you made a typo it should work. And yes, if there is another call to the “woocommerce_thankyou” action that might affect the behaviour of the snippet. Try playing with priority in that case e.g. “5”:

      
      add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom', 5);
      
      
  58. Hello,

    we use event on plugin using woo commerce for final checkout.

    When user pay then paypal redirect him in an automated generated page, how can we avoid that and redirect paying user to a thank you page where we can track affiliate sales (we have that code so we need a thank you page to track affiliate’s sales)

    Please help us!

    1. Hey Fabio, thanks for your comment! I’m not sure I understand the line “we use event on plugin using woo commerce”… could you explain that again? Thanks!

    1. Thank you Fred! Appreciate your feedback 🙂

  59. Hi I am getting error PHP Notice: WC_Shortcode_Checkout->output was called with an argument that is deprecated since version 2.1! “order” is no longer used to pass an order ID. Use the order-pay or order-received endpoint instead. in /home/xxxx/public_html/wp-includes/functions.php on line 3732

    How i can fix this

    1. Hi there Vimarc 🙂 Did you solve this already?

  60. Hello , when a client make a purchase they check out using Paypal leaving my site, is the right way to do it is to setup the return page on Paypal and that page will be the thank you page? or if i post your code in my function.php i assume in the bottom that will do it? I’m trying to calculate conversion with google analytics which require putting google code in the thank you page. thanks for your help in advance

    1. Wesam, thanks for your message! Yes, if you use PayPal, the thank you page you enter in the code will be the thank you page customers see after they pay. You can paste the code at the bottom of the functions.php. For the conversion code, because you’re redirecting users to a custom thank you page, you can simply add the code to that page 🙂

  61. Hi, thanks for the clear information about this. However, after I completed the checkout form and redirected to the thankyou page, why there’s no email confirmation about the order receipt like it used to. Any other things, I need to do for this problem?

    1. Auliana, thanks for your feedback! The email should be independent from the URL of the thank you page or the fact we’re adding the action. Is this issue still happening?

      1. Hi Rodolfo. I haven’t received any emails either once I added the code, however it’s redirecting perfectly THANK YOU! Do you know if this code effects the autoresponers from woocommerce?

        1. Hey Jayne, thanks so much for your comment. As I said, this should be totally independent from the email notifications. Would you be able to tell me which email are not sent if you add the code? Thanks 🙂

  62. Hi Rodolfo Melogli,
    I have a problem with the redirection part. Actually what i want to do is,
    Customer adds to cart> Customer Completes Cart> Customer clicks on “Proceed to PayPal”> “Thank you” page opens in my site. No need to visit Paypal.com. I want it to be a custom page and only for the “paypal” payment option. Is it possible anyway?
    Thanks a lot

    1. Hi Rohan thanks for your enquiry. The answer to any questions related to WordPress/WooCommerce is always YES – it is possible to do what you want. However this is pretty custom and unfortunately I can’t cover it here. Thanks anyway!

  63. Hello Rodolfo Melogli, I have a question regarding woocommerce product. Suppose we have order a product and when i login to my account there i can see my order detail with product links. so if i delete that product lator on and customer open product link that i deleted then is there a possible to redirect custom thankyou page.

    Thanks

    1. Hey Sandeep, thanks for your question. This snippet works only when you buy the product, hence you cannot access the thank you page from the “my-account” page after the order is placed. Hope this helps!

  64. Hi, thanks for your help, i was able to make a redirect, but i still can’t get the order details displayed on my custom page, i have tried the PHP plugin that you’ve mentioned, but all i get is this message:
    Thank you. Your order has been received.

    No details about the order at all. Would you be so kind and make a video on how to do redirect and display order details on the custom page please?

    1. Thank you Peter for your feedback! Displaying order details on a custom Thank you page is advanced PHP and if I have time in the future I will create a blog about it. Thank you 🙂

  65. Hi, can I ask if how would I be able to redirect a custom thank you page for a specific product after purchase? payment gateway used is paypal.

    1. Hello Rey thank you for your message. Of course, what you’re asking is possible – I’ve done this for a client already! The major problem is you have to define what happens if more than 1 product is in the cart 🙂

    2. Rodolfo,

      I am trying to do this as well. Do you have code already typed out like above that we can put in to make this happen?

  66. Rodolfo thanks so much… fixed my problem immediately.

    1. Thank you so much Peter!

  67. hi i saw you have a function to pass order id in redirect thank you page, can you be clearly give me the coding to get the order id to appear on the custom thank you page, ( I’m new to wordpress and php) please help

    1. Yes, once you pass the order id to the new page (for example by using $url = ‘https://yoursite.com/custom-url’ . ‘/?orderid=’ . $order_key) you can simply “get” it like this:

      echo ‘Order ID = ‘ . $_GET[“orderid”]

      Hope this helps!

  68. Hi,
    Can i add a key=wc_order_0000000000000 in url like default Thank You Page ?

    1. Hello, thanks for your comment!

      You should be able to assign the order key to a variable:

      $order_key = get_post_meta( $post->ID, ‘_order_key’, true );

      After that, you can build your redirect URL like this:

      $url = ‘https://yoursite.com/custom-url’ . ‘/?key=wc_order_’ . $order_key;

      Hope this helps 🙂

  69. thanks for the info but please how can i add a ShareAsale html code for affiliates to my check out endpoint i.e the thank you page.

    1. Of course Ruth. If you’re redirecting to a custom page, you can edit the PHP or HTML of that page and add your conversion tracking code. Let me know how you get on!

  70. is giving me this error in the log

    [14-Nov-2014 23:58:33 UTC] PHP Parse error: syntax error, unexpected ‘text’ (T_STRING), expecting ‘,’ or ‘;’ in /home/sold****/public_html/wp-content/themes/so****ro/functions.php on line 148

    any idea?

    1. It seems you forgot a comma somewhere in your code. Can you tell me what exactly shows on line 148 of your functions.php? Thanks 🙂

  71. Thanks for your help. I tried that plugin but it still didn’t pull in the order details. I have sent in a ticket to WooCommerce support to see if they can help.

  72. This worked awesome. Thank you! But just one question, please. How do I include the customer’s order details on the custom page they are redirected to?

    1. Excellent, thanks Jason! The answer is actually very simple – just copy what’s inside the thankyou.php page under Woocommerce/Templates/Checkout 🙂

      1. …and paste it where? To the bottom of the functions.php?

        1. No Jason, I meant to put that content inside the thank you page you’re redirecting to

          1. But to pull in their order details (product, tax, shipping cost) it would require the PHP and you can’t paste the PHP right into the Page Editor in WordPress. So, I am asking how can we pull in their order details. The PHP that is in the thankyou.php is definitely the code we need to show on the custom Thank You page, but how do I get it to show?

            1. I see what you mean 🙂 Well, there is a way to put PHP in a WordPress page, check this plugin: https://wordpress.org/plugins/allow-php-in-posts-and-pages/

  73. Hello Rodolfo,
    Thank you for this post. Is there a way to redirect the order received page per product? Feel free to email me. Thank you.

    1. Jakub, thank you so much for your comment! In answer to your question, YES of course that is possible. On November 4th I will publish an article on how to programmatically add a coupon if a product in in the cart. By putting together this and that snippet you should achieve what you’re looking for. Thank you!

      1. Hello Rodolfo,
        Thank you for your response. Looking forward to it 🙂
        Jakub.

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 *