WooCommerce: Change “Return to Shop” URL

This simple snippet will make sure you can send users back to a custom page as opposed to the shop page when the Cart is empty. In this particular project, client had no shop page so we wanted to send users back to the homepage instead.

As usual, it’s a couple of lines of PHP, without the need to override templates or even worse to edit core WooCommerce. Enjoy!

WooCommerce: edit return to shop link

PHP Snippet: Change “Return to Shop” Button Link – WooCommerce

 * @snippet       Change return to shop link, send to homepage instead
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @community     https://businessbloomer.com/club/

add_filter( 'woocommerce_return_to_shop_redirect', 'bbloomer_change_return_shop_url' );

function bbloomer_change_return_shop_url() {
   return home_url();

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: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
  • WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart
    This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. Here’s how we show a simple message on the […]
  • 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: Weight-Based Shipping Methods
    With WooCommerce you get 3 default shipping methods: Flat Rate, Free Shipping, Local Pickup. For each one you can define a cost, however there is no way to set up some “weight” restrictions. So, what if you want to display a rate for orders below 10 kg, and another shipping rate for orders above that […]
  • WooCommerce: Hide Shipping Method If Shipping Class Is In The Cart
    Our goal is to check if a Product with a specific Shipping Class is in the Cart, and consequently disabling a shipping rate such as Free Shipping if this is true. This is super useful when there are multiple items in the cart and you don’t want to give free shipping for certain orders for […]

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

60 thoughts on “WooCommerce: Change “Return to Shop” URL

  1. Still works. Awesome work! Thank you!

      1. Work well for the “return to shop” button, but when I click the empty cart icon, the pop-up form contain a return link, and this is NOT affected by the snippet it seems?
        Thanks πŸ™‚

        1. This doesn’t look like default Woo, I don’t think there is an empty cart button?

  2. HI, Thanks you so much It’s work like a charms. Awesome.

  3. Worked great – I actually added in this snippet into a plugin called Code Snippet and it worked really well. Question: can we add anything to this snippet that would also change the text on the button?

    Thanks, excellent work.

    1. Thanks Bijal. No, you’ll need to target a different filter hook

  4. Worked for us. Very useful thanks πŸ™‚

    1. Cool

  5. Thanks. You are bravo!

    1. Grazie!

  6. Bonjour Rodolpho !
    Je viens d’essayer ce code dans mon site et Γ§a marche parfaitement sans erreur.
    Vraiment merci de nous Γ©clairer.

    Merci encore !

    1. Merci!

  7. Thanks for this code snippet. I used it today, 11th June 2020, on a new site I’m working on (WordPress 5.4.2) and it worked perfectly. It was great to tick off a ‘To Do’ item so quickly and easily. Many thanks.

    1. Excellent!

  8. Hi! First of all thanks for sharing.

    I just tried to apply this on a theme called “gehou” I received along buying a course on udemy.

    This was my first try of changing any code, I have no experience in this area.

    I always get the same error code, whatever I try:

    “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.”

    Maybe you have an idea what could be the problem?

    1. I just fixed it, with the code snippet it worked directly.

      Also found out later that at woocommerce – settings- products you can change the shop page.

      So if you have created a new shop page, you can choose it there.

      1. Update: my idea did not work unfortunately.

        Gonna stick to usin the code snippet plugin. Works fine.

        1. Great!

  9. What exactly am I supposed to copy? A little confused

    1. Hey James, please sign up with CustomizeWoo.com free edition and take a look there

  10. it worked for me.
    Thanks for the help.

    1. Great!

  11. Great!!! It’s work veeeeeeeeeryweeeeeeeel

    1. Ahah thank you

  12. What if I want to override any /shop/ reference?

    I tried to set up a 301 redirect but that didn’t work. Can I use this function somehow?

    1. No you can’t, sorry πŸ™‚

  13. Rodolfo, you really are amazing! This works great. I am so happy I found your site!!! Thanks for what you do!

    1. Great!

  14. Working Feb 2019 Thx!

    1. Excellent!

  15. Hi,

    ist working for me but only if theres no product into the cart. if there is a product, the button link is still the old one.
    Do you know how i can fix this?

    1. Hello Philipp, thanks for your comment! There is no “return to shop” button if the Cart is not empty… or am I wrong?

  16. Thanks Rodolfo,
    Its work DONE for me, i successfully redirected to a custom shop page instead of Default Shop page withing editing any original file.
    Really you are a amazing man, i am really grateful to you for this great help. i have completed my First WooCommerce project with the help of your Custom Code.
    Love you and Respectful to you.
    Kind Regards,

    1. Awesome πŸ™‚

  17. It worked perfect. God bless you brother. I tried to use my Elementor plugin to design the shop but it did not work, so I used this link: return home_url(store); and it’s working perfect!!! Thank you so much!!!

  18. what if i want to remove it all together since i am making a custom page

    1. Hazo, 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. August 2017 and it still works a charm, thanks!

  20. Hello,

    What is the part, “bbloomer_change_return_shop_url()”?

    Why is “bbloomer” in the code?

    Does this somehow create a link for code or whatever from the bbloomer website?

    1. Hey Puddin, thanks for your comment! That’s just the name of the function, you can rename it if you wish πŸ™‚

      1. I had the same question and realized it’s better to keep it in the code exactly as it is. So in case you need to refer back to where you got it from you can always come back to this site! It helped me several times already to know that a specific piece of code came from this site πŸ™‚ Thanks Rodolfo – your articles are GREAT!

        1. Cool!

  21. Hello,
    When I put this snippet in and click the save button I get this message
    Parse error: syntax error, unexpected ‘:’ in /home/u/u2679944/www/xn--ullbdd-eua.se/wp-content/themes/divi-child/functions.php on line 47
    And now I can not login to my site either can I see the site.
    What is wrong????

    Best Regards

    1. Hey Greger thanks for your comment! As you can see there is no “:” in my snippet, so you must have pasted the snippet wrongly. I suggest you access your site via Hosting/File Manager or FTP to remove the snippet, so that your site will be back up to normal. After that try to paste it again by paying more attention and it should work πŸ™‚ Let me know!

      1. The problem is solved. ThankΒ΄s

  22. can you please tell me where to put this code And if this works with WPML ?

    1. Hey Sam, thanks for your comment! You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/. And yes, it should work with WPML, I don’t see why not πŸ™‚ Hope this helps!

  23. Yeahhhh that is amazing.
    Worked fine for me.

    Thanks for the solution ..

    1. Brilliant, thanks a lot for your feedback Dimitri!

  24. Hi. Where do we need to place this code? finction.php?

    1. Indeed Nicu, in the functions.php of your child theme. Watch this tutorial if you don’t know what that means. Thanks for your comment!

  25. What if you want to send them to a different page from the home page? What’s the syntax to do that, instead of using home_url?

    1. Valerie, thanks for your question! You can simply put a URL in there:

      // Change return to shop link, send to URL instead
      function bbloomer_change_return_shop_url() {
      	return 'https://#######';	
      add_filter( 'woocommerce_return_to_shop_redirect', 'bbloomer_change_return_shop_url' );
  26. Hello Rodolfo!

    Thank you for the useful snippet! I was wondering if you also knew of a filter to change the button text as well…

    Thanks again!

    1. You’re welcome Sharon! In order to change the text you can take a look at this: https://businessbloomer.com/translate-single-string-woocommerce-wordpress/

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 *