In today’s article, I’ll walk you through the step-by-step process to change the WooCommerce ‘Return to Shop’ URL on the cart page. I’ll share the code snippet that you can simply copy and paste to your store to not only change the ‘Return to Shop’ URL but also the text.
The ‘Return to Shop’ is a button that shows on the cart page if the cart is empty. You may want to change its text or the URL to redirect customers to a different page other than the shop page.
Before diving into the actual article, let’s take a look at a few reasons and benefits of changing it.
On This Page
What Are the Benefits of Changing the WooCommerce ‘Return to Shop’ URL?
The following are a few benefits due to which you should change the WooCommerce ‘Return to Shop’ URL and the button text.
- Happier Customers: Changing the button can help guide them to the right place, making shopping more enjoyable.
- More Sales: If the button takes customers to on sales or new products, they might see something they like and buy more.
- Helpful Suggestions: Customers may love it if you change the link to more relevant, helpful, or interesting products.
Now, without any further ado, let’s jump into the actual tutorial to change the WooCommerce ‘Return to Shop’ URL and the button text as well.
How to Change the WooCommerce ‘Return to Shop’ URL?
WooCommerce is a very dynamic platform and it gives you several features to add to your online store for better customer experience. You can also add custom features to your WooCommerce store using custom code.
Here I’ll share the code snippet that will help you to customize the ‘Return to Shop’ button on the cart page. I’ll also explain the code for your better understanding.
1. Code to Change the WooCommerce ‘Return to Shop’ URL
The following code snippet will help you to change the ‘Return to Shop’ URL and button text on the cart page. Make sure to replace the home_url() with the URL to which you want to send your customers. The URL should be wrapped within quotes.
Also, don’t forget to change the ‘Go Back to the Product Page’ text with whatever you want to set. It depends on your requirements if you want to change it or not.
// Change the URL of the "Return to Shop" button
function aovup_custom_woocommerce_return_to_shop_redirect() {
return home_url(); // You can change this with the URL to which you want to redirect the customers. Make sure you add the URL within the quotes like 'https://mywebsitesite.com'
}
add_filter('woocommerce_return_to_shop_redirect', 'aovup_custom_woocommerce_return_to_shop_redirect');
2. Code to Change the WooCommerce ‘Return to Shop’ Text
// Change the text of the "Return to Shop" button
function aovup_custom_woocommerce_return_to_shop_text( $translation, $text, $domain ) {
if ( 'woocommerce' === $domain && 'Return to shop' === $text ) {
$translation = 'Go Back to the Product Page'; // Change 'Go Back to the Product Page' to your desired text
}
return $translation;
}
add_filter( 'gettext', 'aovup_custom_woocommerce_return_to_shop_text', 30, 3 );
3. Understanding the Code(Optional)
This code is written in PHP and is used to customize a part of a WooCommerce website. Let’s break it down:
3.1. First Part: Changing the URL
- The function aovup_custom_woocommerce_return_to_shop_redirect is defined. This function will be used to change the URL of the “Return to Shop” button.
- Inside the function, return home_url(); is saying that the button should point to the home page of the website.
- The line add_filter(‘woocommerce_return_to_shop_redirect’, ‘aovup_custom_woocommerce_return_to_shop_redirect’); tells WordPress to use this custom function to change the URL of the “Return to Shop” button.
3.2. Second Part: Changing the Text
- Another function aovup_custom_woocommerce_return_to_shop_text is defined. This one will change the text displayed on the “Return to Shop” button.
- The if statement checks whether the text to be changed belongs to WooCommerce and if it is ‘Return to shop’. If both are true, it changes the text to ‘Go Back to the Product Page’.
- The function then returns the modified text.
- The line add_filter( ‘gettext’, ‘aovup_custom_woocommerce_return_to_shop_text’, 30, 3 ); tells WordPress to use this custom function to change the button’s text.
In simple terms, this code has two main jobs: it changes where the “Return to Shop” button will take the user, and it changes the words displayed on the button to ‘Go Back to the Product Page’.
4. Paste the Code to Your WooCommerce Store
There are several methods to paste the code to your store, and you can use any of the available methods. Here’s a guide that will tell you how to paste the code to your store.
For this tutorial, I used the plugin to add the code snippet to my demo store.
5. Final Results
Now, let’s test the final results.
To test it, visit your store’s checkout page and make sure the cart is empty otherwise, you won’t be able to see the ‘Return to Shop’ button.
You will notice that the button text has been changed to the ‘Go Back to the Product Page’ and it is redirecting to the homepage or the URL that you specified at the backend.
I tested it, and I was being redirected to my homepage as I specified in the code. Also, the button text was changed.
Conclusion
That’s it for today’s article.
I hope it was helpful to you and you were able to change the WooCommerce ‘Return to Shop’ URL on the cart page to redirect customers to a different page other than the shop page.
It will give a more personalized experience to the customers and you may be able to increase your sales as well. You can change the link to the product page or the offer page to encourage customers to purchase.
Moreover, the changing of the button text will also play a great part in encouraging the customers to click the button if their cart is empty.