Change the “Return to shop” button URL in the cart page

If you turn on the option to redirect to the cart page after adding a product to the cart, you will have a nice little button that invites you to Continue Shopping. You can change this URL to anything you want!

When the cart is empty, it shows a button to “Return to shop” instead. By default, as it says, it returns to the shop page selected in the settings. But you can change that URL to something else.

To do so, add this code to your functions.php file located in wp-content/themes/your-theme-name/:

This will redirect to the URL specified in the code.
What if you want to dynamically return to the page previously visited?

Use this code instead:

Be aware that it will return to the previous visited page. So if you were on the cart page while it was not empty, and then removed everything in it, the referrer URL will be the non-empty cart page.

You would need to add some additionals check to be sure that the referrer URL is not the cart page.

Contribute to Improving This Blog

Did you enjoy this article? Was it helpful? Contribute to help me writing more articles! The funds collected from this blog are reinvested directly into improving my skills or the blog so that I can provide more and better content!


Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount


Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Do you prefer using cryptocurrency? I’ve got you covered! You can donate at the following wallets:

  • BTC: bc1q87nxpdpqw323ccmerrzyeffs72wnxpw93x7pzk / 17Gtc5e8yoh2LZzokoyK8P5DWbToBwztok
  • ETH: 0xA5C89Be1df2896C3942DBEf751cCeacC7929388b

More Posts That You Might Like…

95 responses to “Change the “Return to shop” button URL in the cart page”

  1. Hi, thanks so much for sharing this ! I’ve been looking for months to get that “previous page” link trick !! Worked perfectly, thank you thank you !

    1. Hi Daniel!
      Thanks for the feedback! I’m happy that my post helped!

      1. But
        What additionals check I have to add to redirect the previous page if the Cart would be empty and how. Can you Give the whole structure but I am from a developer background.
        You can email me the structure at my email account (
        Please help me..

  2. I can not find the file functions.php tell me where he is?

    1. It is located inside your theme folder, in wp-content/themes/your-theme-name/ where your-theme-name is the name of the active theme.

  3. It works!
    Thanks alot buddy! Really appreciate.

    1. You’re welcome 😉

  4. Copy and pasted the code snippet directly and doesn’t work. Instead, it shows the line of code on the top of my website when visited.

    1. Hi Coy,

      Instead, it shows the line of code on the top of my website when visited.

      That means that you pasted it in the wrong place. If at the end of your functions.php file you have the sign ?> make sure to paste the code before the sign.

      1. THAT helped a LOT
        thank you!

  5. Thanks for the code.
    For some reason after installing the code, when I click on the “Return To Shop” button, the cart page just refreshes and I am not carried to the URL that I placed in the code for the re-direct.

    1. Hi Gene,
      Did you use the first or the second snippet?

      The second will redirect to the cart again if the previous page visited is the cart page.

      For example, if you visit the cart, then delete an item in it, you get the Return button.

      In this case the previous page visited is the cart page, so it will redirect always there.

  6. Hi, what to do in case that I have Polylang plugin and need to define 2 different links? the default language work perfect, the problem with the 2nd lang.

    1. Hi Nathan,
      I’m not sure about Polylang, I never used it. With WPML you would check the constant ICL_LANGUAGE_CODE and based on that you would return a different URL.

      Something like:

      if ( ICL_LANGUAGE_CODE == 'it' ) {
        return "Italian URL";
      } else {
        return "English URL";

      You can change the part with ICL_LANGUAGE_CODE with what Polylang uses to detect the current language.

  7. Hey man

    I know its an old post, but when i add your code to the function.php file i get a blank page, any ideas why?

    1. Hi Evan,
      Thanks for writing!

      It means that there’s an error somewhere. Can you check your error log an see if there’s any Fatal error entry?

  8. Hi

    I have used the first code and put in the address for our shop page, but now when I empty the basket I do not get a return to shop button….any ideas why?

    Thank you for your help

    1. Hi Sarah,
      It could be a conflict with your theme.

      Try to disable it and enable a different one and see if you can reproduce the issue.

  9. Hi again

    We have a wholesale order form on our site as well as retail shop page.

    As I stated above that the return to shop button has disappeared since putting in the code.

    As there was no button to return to shop after basket is emptied, I changed the link to our wholesale order form so that when wholesale customers are on their account page and if they click on orders and have no orders there is a button which says go shop, now this link goes to the wholesale order form , which is great, but it also goes to the wholesale order form for retail customers.

    Is there any way of telling it to go to our shop page for retail customers and not to the wholesale order form?

    1. Hi Sarah,
      I’m sorry but I’m not sure to understand how the website works. I don’t know how you create this contact form, therefore I’m not really able to help you with that 🙁


  10. How would this work with a multi-site install when the site name cannot be hard coded in code?

    1. Hi Paul,
      You can use the function get_blog_details() to retrieve the blog data.

      1. Don’t know whether get_blog_details has been deprecated or ???, but it threw an unknown function error.

        I suggest trying:
        return get_site_url().'/your-page/';

  11. Doing this exactly as the article describes (copy and pasted) outputs the following warning in the href of the return to shop link:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wc_empty_cart_redirect_url’ not found or invalid function name in /wp-includes/plugin.php on line 235

    1. Hi Mike,
      That error means that the system can’t find the function wc_empty_cart_redirect_url. I guess it is in the wrong place or partially copied.

  12. Great bit of code – I love the internet – can usually find the answer out there somewhere!
    Thanks for the code and the easy explanation on how to use it (one day i may even learn php …. until then .. i will rely on good people like yourself!)

    1. Awesome Steve, thanks for the kind words!

  13. Femke de Coninck Avatar

    Thanks, great code!

    1. You’re welcome Femke!

  14. Thank you for this code, was a big help!

    1. You’re welcome Chris!

  15. hi, im using a divi them, im not sure where to paste the code, above you mentioned that it should go just before ?> but i dont have that at the end of my functions.php, So can i paste it anywhere? Thanks in advance

  16. Nevermind, i tried just adding it to the bottom and it worked, thanks so much 🙂

    1. Yeah if there’s no ?> just add the code at the end of the file!

      I’m happy you figured that out!

  17. Thank you for the life saver!

    Can you share with us if there is a way to rename the button? Ie instead of “Return To Shop” I would like to call it “Back To Plans Overview”?

    1. Hello Dean,
      The only way to do that is to override the template cart-empty.php from WooCommerce to your theme, and then edit the text in your theme’s template.

      You can learn how to override templates in WooCommerce here:

  18. Really great thanks! The 2nd snippet worked perfectly!

    1. You’re welcome Chris!

  19. Thank you for this code………..

    1. You’re welcome mounish!

  20. Fantastisc! It worked pretty well. I have been looking for this code for ages….Thank you very much.

    1. You’re welcome Angelo!

  21. Hi Nicola, is it possible that this cannot be used in alt themes? I have some trouble finding the code snippet in the functions file.

    1. *all themes that is 🙂

    2. Hey Martin,
      Sorry for the late reply.

      You won’t find the snippet in your theme’s functions file, you’ll have to add it.

  22. Thank you sir, it was a big help to me. 🙂

    1. You’re welcome Attila!

  23. Thanks its very work

    1. Awesome ihsan! I’m happy it works for you!

  24. Hi i try to empty cart from another page, not in the cart page and Without plugin!

    Do you have a sollution for this as well?

    i did try this:
    * Clear Cart for WooCommerce
    add_action( ‘init’, ‘woocommerce_clear_cart_url’ );
    function woocommerce_clear_cart_url() {
    global $woocommerce;

    if ( is_page('9') && isset( $_GET['empty-cart'] ) ) {


    but it does nothing, the page where this should come is page id 9


  25. Hi,
    I want to use the second code snippet but as you said i dont want to redirect them to the cart page if they have just emptied their cart? what additions checks do i need to add??

  26. This works perfectly! Thanks Nicola!

    1. You’re welcome Kodi!

  27. Thanks!
    Changing the “Return to shop” URL works fine.
    Maybe… do you have a solution for changing the breadcrumb URL (between Home and Cart) to the new URL too?

  28. Hi
    Thanks for covering this, been looking everywhere for this solution. I tried the second code and unfortunately I got stuck in the empty cart loop. Being a total beginner with coding could you please give us ammeters a few pointers on the additional checks?
    Thanks in advance

    1. Hello AJ,
      You can check if the current URL is the same as the HTTP referrer, and in that case redirect somewhere else instead.

      You can find here a tutorial about how to know what the current URL is:

  29. Grazie Nicò, funziona.

    Sai come si cambia il testo del bottone “Torna al Negozio” ?


    1. Ciao,
      non ci sono filtri, quindi devi modificare il template cart-empty.php.

  30. THANK YOU SO MUCH FOR THIS!!!!! been looking for this FOR AGES!!


    1. You’re welcome!

  31. Hello! I’m using a plugin called Code Snippet to implement the code and it isn’t working. The “return to shop button” is still very much in the cart page. I used the first code .

    Thanks in advance.

  32. Hey I lifted the code directly from your post and placed it as suggested and it worked great!!! Thanks! Was driving me crazy! JB

    1. You’re welcome James!

  33. Thank so much! The code worked perfectly. I was worried at first because I don’t know mcc about code and didn’t want to make a mistake. But I added the code at the end and changed to my domain…worked perfectly!!!

    1. Awesome Rizzo! I’m happy it works for you!

  34. I’m using the Code Snippets plugin as well and it’s not working. do i have to edit the functions.php file in order for this to work? thx!

    1. Hi Mary,
      I checked the code again and it really should work properly. I don’t know this plugin Code Snippets, so I’m not sure if it will work with it or not.

      Try to add it to functions.php and let me know, please!

  35. Hi! Tried this code and got an error that I “cannot redeclare the wc_empty_cart_redirect_url function”. Is that a theme issue or did I enter something incorrectly?

    1. Hi Joslin,
      Your theme or maybe another plugin already is using a function named wc_empty_cart_redirect_url. Make sure that you didn’t write it twice in functions.php, or just change the function name to something else in this snippet.

      I checked in WooCommerce and it does not use a function with that name already.

  36. awesome code! worked perfectly

  37. I added the snippet and got an error that said the system reverted back to the original code because the servers couldn’t be found.

  38. Here is the message:
    Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.

    Should I just try on a different browser? I am using Chrome right now.

    1. Hi, a different browser will not help in this case because it is a server error. Most probably you added the code in the wrong place or edited it wrong.

      Are you adding it at the end of the file functions.php in your theme’s folder? If the file ends with a ?> make sure to add the code before that sign.

  39. How can I move to the particular page instead cart. I want my client to redirect to the pricing table page?

    1. Hello,
      In the first snippet example, I set up a simple URL. You can use that to simply set the URL of your pricing page.

  40. Magnifico!
    Venho buscando por isso alguns dias.


  41. Saved my day. Thanks a bunch!! 🙂

    1. You’re welcome!

  42. Hi Nicola,
    A used this solution and it worked fine. Thanks for it 🙂
    But some days ago a just updated the woocommerce (Version 3.3.5) and now the code does not work.
    Can you help me why not?
    Maybe the WC changed something important code…???

    1. I solved it 🙂

  43. I cannot get this to work!!! using following code

    function wc_empty_cart_redirect_url() {
    return ‘’;
    add_filter( ‘woocommerce_return_to_shop_redirect’, ‘wc_empty_cart_redirect_url’ );

    always redirects to

    placed in fuction.php

    want ulr:


    function wc_empty_cart_redirect_url() {
    return ‘’;
    add_filter( ‘woocommerce_return_to_shop_redirect’, ‘wc_empty_cart_redirect_url’ );

    but still no joy

    1. Hi Jodey,
      I’m not sure why it is not working. The code is correct, and it’s so simple that there’s no margin for errors.

      Please try switching to the theme TwentySeventeen and see if you can reproduce the issue. if not, the issue is with the theme you are using. In this case you would need to contact the theme author, inform them about the issue and ask them to fix it.

      I also suggest to disable all non Woo-related plugins and check the issue. If you can’t reproduce it, enable the plugins one by one and see which one is causing the issue.

  44. greate

  45. Thanks for the snippet!

    Say you had multiple user roles that you wanted to take back to their appropriate dashboards, do you know how the code would look to achieve that? Thanks for your help!

  46. It’s still useful today… Thank you for your generosity! What a DUDE!

  47. didn’t work for me. Redirects to cart page as discussed.

  48. This worked for me today.

    Thanks a bunch!

  49. Hey Nicola! Code is still working great. Thanks for sharing your infinite WooCommerce knowledge! I hope all is well. <3

    1. Hey Maria, I am glad, thanks for confirming! All is well so far, I hope you are doing good too!

  50. Even in 2020 this is still relevant, man you deserve an accolade for this, it works perfectly

    Thanks and i have bookmarked your blog hopping to get more from you

  51. Is there a way to make product cross-sell on the fly? In other words on the cart page have a static Id that you can make a cross-sell for any product in the cart.

  52. Hi Nicola, the code worked for me. I will be coming here more often to find such small snippets to help me with my wordpress website. Thank you.

  53. […] the past we discussed about how to change the Return to Shop button URL in the Empty Cart page. Today we will learn how to change the Continue Shopping button URL always on the cart […]

  54. This is fine if the cart is empty, but it doesn’t work if there’s an item in the cart. Please can you tell me what the code is for a cart that isn;t empty?

    For example but not correct!!!!: wc_full_cart_redirect_url


    1. I look forward to the code to achieve this but in the meantime I’ve found a plugin to do it.

      I’ve managed to change the return to shop button URL in a ‘Full Cart’, (Cart with one item in it), by editing it in the StoreCustomizer Plugin which was free for this:

      WordPress ▸ Appearance ▸ Customise ▸ StoreCustomizer ▸ Cart Page

      Button Type ▸ Add Custom URL

      Button Custom URL ▸ enter your URL in box

      StoreCustomizer, Previously known as “WooCustomizer”:

Leave a Reply



Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at

%d bloggers like this: