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-change-return-shop-url
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
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_return_to_shop_redirect', 'bbloomer_change_return_shop_url' );

function bbloomer_change_return_shop_url() {
   return home_url();
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). 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.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

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.

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

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

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

  3. Worked for us. Very useful thanks ๐Ÿ™‚

    1. Cool

  4. Thanks. You are bravo!

    1. Grazie!

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

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

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

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

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

    1. Great!

  10. Great!!! It’s work veeeeeeeeeryweeeeeeeel

    1. Ahah thank you

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

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

    1. Great!

  13. Working Feb 2019 Thx!

    1. Excellent!

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

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

    1. Awesome ๐Ÿ™‚

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

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

  18. August 2017 and it still works a charm, thanks!

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

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

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

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

    Thanks for the solution ..

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

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

  24. 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' );
      
      
  25. 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!
    Sharon

    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? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. 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 BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

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