To change the "Return to Shop" link in WooCommerce, you can customize the URL
where this link redirects customers when their cart is empty. By default, it
points to your main shop page, but you can modify it to any page you prefer
(such as a promotional page, category page, or homepage) by adding a small PHP
snippet to your theme's functions.php
file or via a code snippet plugin.
Steps to Change the "Return to Shop" Link URL
-
Access Your Theme’s functions.php File
- Go to your WordPress Dashboard.
- Navigate to Appearance > Theme Editor.
- Open the
functions.php
file of your active theme.
-
Add the Custom PHP Code
Insert the following code snippet to change the "Return to Shop" link URL:php add_filter('woocommerce_return_to_shop_redirect', 'custom_return_to_shop_link'); function custom_return_to_shop_link() { // Redirect to a custom URL, replace '/your-custom-page' with your desired path return home_url('/your-custom-page'); }
- Replace
'/your-custom-page'
with the slug or path of the page you want customers to be redirected to. - Alternatively, you can use WooCommerce functions like
wc_get_checkout_url()
to redirect to the checkout page orget_permalink(woocommerce_get_page_id('shop'))
for the shop page.
- Replace
-
Save the Changes
- Click Update File to save your changes.
-
Test the Link
- Add a product to your cart.
- Remove the product or go to the empty cart page.
- Click the "Return to Shop" link and verify it redirects to your specified page.
Example: Redirect to Checkout Page
php
add_filter('woocommerce_return_to_shop_redirect', 'custom_return_to_checkout_link');
function custom_return_to_checkout_link() {
return wc_get_checkout_url();
}
Notes
- Always back up your site before editing theme files.
- You can also change the text of the "Return to Shop" button by additional customization if needed.
- If you prefer not to edit theme files directly, you can use a code snippet plugin to safely add this code.
This method leverages the WooCommerce filter
woocommerce_return_to_shop_redirect
to easily customize the destination of
the "Return to Shop" link