Change Continue Shopping Link in WooCommerce

If you have the “Redirect to the cart page after successful addition” setting active when you add a product to the cart you should be taken to the cart page.

Continue Shopping Link

Continue Shopping -link-on-cart-page

When you're on that page you'll probably notice a little button that say's “Continue Shopping”. Now by default this button takes you back to the product you were on. You can, of course, change this to any destination you want with a filter.

In this case I want to change the location from the original product to the main shop page. You can find that page with the really useful wc_get_page_id function.


<?php
/**
* Return the permalink of the shop page for the continue shopping redirect filter
*
* @param string $return_to
* @return string
*/
function my_woocommerce_continue_shopping_redirect( $return_to ) {
return get_permalink( wc_get_page_id( 'shop' ) );
}
add_filter( 'woocommerce_continue_shopping_redirect', 'my_woocommerce_continue_shopping_redirect', 20 );

26 thoughts on “Change Continue Shopping Link in WooCommerce

  1. Sorry for my ignorance but where would one paste this code? I am wanting to do exactly that, redirect to the shop page instead of the product.

    Thanks!

  2. I am trying to change the redirect to shop that occurs when you empty your cart and the ‘return to shop’ button appears.

  3. Thank you so much Patrick for the solution.

  4. Hi, what if I want to change the name of the button also?

  5. Perfect, thanks a bunch:)

  6. Yes! It’s finally working! Thank you so much! 😉

  7. Thanks for the help!

  8. This is not working for me I am on 2.3.5.

    I checked in wc-cart-functions.php and the value of return_to is null, so it always redirects to cart page or previous page which is product details page


    $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
    $message = sprintf('%s %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );

    What am I doing wrong?

  9. how to redirect to category instead of single product page

  10. Great! Just a heads up in your snippet you are using the correct new wc_get_page_id function but you mention the deprecated ‘woocommerce_get_page_id’ function in the actual post content. It may confuse some people.

  11. Hi, how could i remove the button?

  12. Hello! It’s very interesting, but I’d like to know if it’s possible to add another location. In my case, I have a product with several accessories below, if the client click on an accessory and add to cart, when he click “continue shopping” is redirected to the accessory (last product he has visited), not to the main product with all the accessories. I’d like he is redirected to the main product with all the accessories, so he can go on looking and buying them. How can I change it? Is it possible??
    Thank you very much!

  13. HI

    Sorry, but excatly what in the snippet should I change to “my own data” so to speak… ?

  14. thanks for your sharing,… !!

    any idea how to redirect with ” window.history.go(-2); ”

    ?

    Thank you

  15. I like doing it this way.

    add_action( ‘woocommerce_after_cart_totals’, ‘add_continue_shopping_button_to_cart’ );
    if ( ! function_exists(‘add_continue_shopping_button_to_cart’) ) :
    function add_continue_shopping_button_to_cart() {
    $shop_page_url = get_permalink( wc_get_page_id( ‘shop’ ) );
    if (!empty($shop_page_url)):
    echo ”;
    echo ‘ ‘.__(‘Continue shopping’, ‘woocommerce’).’‘;
    echo ”;
    endif;
    }
    endif;

  16. Thanks Patrick. I’ve watched your videos on Lynda.com and they are excellent. I appreciate this post and it worked like a charm. Thank you!

  17. Sekolah Pramugari

    How to make “Continue Shopping” button return to previous page and not the shop pages?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.