Change return to shop button in empty cart
-
Hi everyone
If you are in the woocommerce cart and remove all items, a button appear which says ‘return to shop’ as I’m not using the Woocommerce shop page but rather my own custom pages which then link to the product pages I can’t have this button going to the shop. I would like this button to actually return the customer to their previous page. I found this code
/**
* Changes the redirect URL for the Return To Shop button in the cart.
*
* @return string
*/
function wc_empty_cart_redirect_url() {
return $_SERVER[‘HTTP_REFERER’];
}
add_filter( ‘woocommerce_return_to_shop_redirect’, ‘wc_empty_cart_redirect_url’ );which I copied into my function.php file. It does work, only it returns you to the cart so you end up stuck in a loop. The blog page I found it on did say “Be aware that it will return to the previous visited page. So if you were on the cart page while it was not empty, and then removed everything in it, the referrer URL will be the non-empty cart page.
You would need to add some additionals check to be sure that the referrer URL is not the cart page.”
Not knowing a whole lot about code, I’m not sure how these additional checks work. I have commented on the post but no reply yet. Can anyone offer me some pointers please?Many thanks in advance
- The topic ‘Change return to shop button in empty cart’ is closed to new replies.