How to Redirect Return to Shop to Custom URL In WooCommerce

WooCommerce Redirect Return to Shop The WooCommerce return to shop button allows users to go back to the shop to continue shopping from the cart or to add more products to the shopping cart. If you want to add redirect to the return to the shop button, you can use a filter hook to change the page where the users are redirected when they click on the return to shop page.

This is button sends customers back to the shop and may not be necessary when you have a single product and want the customer sent to another page. For example, you may want to redirect return to shop to a custom URL where you have another product or custom content.

To create redirect for the return to the shop button, you should locate the functions.php file of the active WooCommerce theme or the child theme where you will add the code snippets shared below.

You can access this file through the WordPress dashboard theme editor – Appearance Menu > Theme Editor. You can also use an FTP access tool like Filezilla as well as File Manager on your web host CPanel.

WooCommerce Redirect Return to Shop

If you want to redirect return to shop to a custom URL, you can use the code snippet below and change the URL to fit your needs.

/**
 * Redirect return to shop button to Custom URL
 *
 * @return $string
 */

add_filter( 'woocommerce_return_to_shop_redirect', 'njengah_redirect_return_to_shop_to_custom_url' );

function njengah_redirect_return_to_shop_to_custom_url() {
        
       return get_site_url(). /custom-url/;
        
}

You should replace the custom-url with the slug of the page you want to redirect the return to shop button.

Redirect Return to Shop to Home Page

For example, this code will redirect the return to shop to home page

/**
 * Redirect return to shop button to Home Page  
 *
 * @return $string
 */

add_filter( 'woocommerce_return_to_shop_redirect', 'njengah_redirect_return_to_shop_to_homepage' );

function njengah_redirect_return_to_shop_to_homepage() {

                return get_site_url();    

}

Redirect Return to Shop to About Us Slug (about-us)

The following code will redirect the return to shop to an about us page with a slug  about-us

/**
 * Redirect return to shop button to About us
 *
 * @return $string
 */

add_filter( 'woocommerce_return_to_shop_redirect', 'njengah_redirect_return_to_shop_to_about_us' );

function njengah_redirect_return_to_shop_to_about_us() {

                return get_site_url() . /about-us/;       

}

Redirect Return to Shop to a Product (product-slug)

The following code will redirect the return to shop to a product with a slug  – product-slug

/**
 * Redirect return to shop button to Product Page 
 *
 * @return $string
 */

add_filter( 'woocommerce_return_to_shop_redirect', 'njengah_redirect_return_to_shop_to_product' );

function njengah_redirect_return_to_shop_to_product() {

                return get_site_url() . /product-slug/;  

}

Redirect Return to Shop to the Previous Page

Another common way of creating a redirect for return to the shop button is to redirect to the page the user had visited earlier. You can create a return to shop redirect to the previous page using the following code:

/**
 * Redirect return to shop button to previous page
 *
 * @return $string
 */

add_filter( 'woocommerce_return_to_shop_redirect', 'njengah_return_to_shop_to_previous_page' );

function njengah_redirect_return_to_shop_to_previous_page() {
          
                return $_SERVER['HTTP_REFERER'];         

}

As you can see from these examples the possibilities for creating a redirect for return to shop are limitless. You can change this code to suit your specific needs.

Conclusion

To create WooCommerce redirect for return to shop URL, you simply need to add the code snippet shared in this post and you edit the custom URL to fit the page you want to redirect the users to.  You may also want to create a WooCoomerce redirect after a successful purchase, I shared in detail how to create such a redirect in this post.