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!

PHP Snippet: Change “Return to Shop” Button Link – WooCommerce
/**
* @snippet Change return to shop link, send to homepage instead
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @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();
}
Still works. Awesome work! Thank you!
Great!
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 π
This doesn’t look like default Woo, I don’t think there is an empty cart button?
HI, Thanks you so much It’s work like a charms. Awesome.
Cool
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.
Thanks Bijal. No, you’ll need to target a different filter hook
Worked for us. Very useful thanks π
Cool
Thanks. You are bravo!
Grazie!
Bonjour Rodolpho !
Je viens d’essayer ce code dans mon site et Γ§a marche parfaitement sans erreur.
Vraiment merci de nous Γ©clairer.
Merci encore !
Merci!
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.
Excellent!
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?
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.
Update: my idea did not work unfortunately.
Gonna stick to usin the code snippet plugin. Works fine.
Great!
What exactly am I supposed to copy? A little confused
Hey James, please sign up with CustomizeWoo.com free edition and take a look there
it worked for me.
Thanks for the help.
Great!
Great!!! It’s work veeeeeeeeeryweeeeeeeel
Ahah thank you
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?
No you can’t, sorry π
Rodolfo, you really are amazing! This works great. I am so happy I found your site!!! Thanks for what you do!
Great!
Working Feb 2019 Thx!
Excellent!
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?
Hello Philipp, thanks for your comment! There is no “return to shop” button if the Cart is not empty… or am I wrong?
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
Awesome π
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!!!
Cool π
what if i want to remove it all together since i am making a custom page
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
August 2017 and it still works a charm, thanks!
Brilliant π
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?
Hey Puddin, thanks for your comment! That’s just the name of the function, you can rename it if you wish π
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!
Cool!
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
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!
The problem is solved. ThankΒ΄s
Great!
can you please tell me where to put this code And if this works with WPML ?
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!
Yeahhhh that is amazing.
Worked fine for me.
Thanks for the solution ..
Brilliant, thanks a lot for your feedback Dimitri!
Hi. Where do we need to place this code? finction.php?
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!
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?
Valerie, thanks for your question! You can simply put a URL in there:
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
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/