WooCommerce: Redirect to Custom Thank you Page

How can you redirect customers to a beautifully looking, custom, product-specific thank you page?

Thankfully you can add some PHP code to your functions.php and define a redirect to a custom URL (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.Β 

WooCommerce Redirect Custom Thank You Page
WooCommerce Redirect Custom Thank You Page

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 3.7
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
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!

“I don’t code – is there a trustworthy plugin for that?”

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 this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a 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.

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

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

  2. 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!

  3. 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

  4. 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!

  5. 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!

  6. 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

  7. 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 πŸ™‚

  8. 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 πŸ™‚

  9. 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

  10. 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?

  11. 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!

  12. 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

  13. This snippet works like charm!

  14. Thank you! It works well.

  15. 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

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

  17. 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 πŸ™‚

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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?

  23. 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

  24. 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 πŸ™‚

  25. 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? πŸ™‚

  26. 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

  27. 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

  28. 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?

  29. 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 πŸ™‚

  30. 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!

  31. 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!

  32. 
    add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
     
    function bbloomer_redirectcustom( $order_id ){
        $order = new WC_Order( $order_id );
     
        $url = 'http://....';
     
        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?

  33. 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/

  34. 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 = 'http://yoursite.com/custom-url?order_total=300&order_number=95';
      

      Let me know!

  35. 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 πŸ™‚

  36. 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 πŸ™‚

  37. 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!

  38. 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 πŸ™‚

  39. 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 “http://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!

  40. Hy

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

  41. 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);
      
      
  42. 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 πŸ™‚

  43. 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?

  44. 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 πŸ™‚

  45. 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 πŸ™‚

  46. 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!

  47. 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!

  48. 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 πŸ™‚

  49. 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?

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

    1. Thank you so much Peter!

  51. 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 = ‘http://yoursite.com/custom-url’ . ‘/?orderid=’ . $order_key) you can simply “get” it like this:

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

      Hope this helps!

  52. 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 = ‘http://yoursite.com/custom-url’ . ‘/?key=wc_order_’ . $order_key;

      Hope this helps πŸ™‚

  53. 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!

  54. 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 πŸ™‚

  55. 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.

  56. 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/

  57. 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.

        1. You’re welcome! πŸ™‚

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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