You can change the WooCommerce shop URL with a filter that WooCommerce provides, this can be helpful especially if you have a one product based shop and you want your users to return to that product and not the default shop page URL.
The filter to use is aptly named – woocommerce_return_to_shop_redirect – add in your themes functions.php
add_filter( 'woocommerce_return_to_shop_redirect', 'st_woocommerce_shop_url' ); /** * Redirect WooCommerce Shop URL */ function st_woocommerce_shop_url(){ return site_url() . '/product/my-product/'; }
So in the above code the filter is run and returns the main site URL with site_url() and then adds on a slug of the page you want – above it goes to a particular product, or you could not use site_url() and just hard code the absolute URL in quotes.
A similar link is also the ‘Continue Shopping’ link which is displayed after am item has been added to the cart – its filter is woocommerce_continue_shopping_redirect – it is displayed when Redirect to the cart page after successful addition is enabled.
add_filter( 'woocommerce_continue_shopping_redirect', 'st_change_continue_shopping' ); /** * WooCommerce * Change continue shopping URL */ function st_change_continue_shopping() { return wc_get_page_permalink( 'shop' ); // Change link }
3 comments
yasir
Thank you so much
chairman likit
Thank you very much
Mary Jo
i cannot get this to work! i’m using woocommerce version 3.2.6 with the jupiter theme, and using code snippets rather than adding the code to the functions.php file. i’ve used code snippets for many things with no issues. any ideas i can’t get this one to work?