Removing Continue Shopping button from Added to Cart Notice
Asked Answered
O

4

9

Currently when someone adds a product to our website it says: "X Product" has been added to your cart | and then has a "Continue Shopping" button in that notice that is on the right.

Since we only sell 2 products we want to remove the continue shopping button completely but still say the rest of the message, and keep "X Product" as a link.

I've been using the following code (but it replaces Continue Shopping with Checkout and I'd prefer to just remove the button completely instead). I just can't figure out how to remove the button but still keep the rest of the message exactly the same:

add_filter( 'woocommerce_continue_shopping_redirect', 'my_changed_woocommerce_continue_shopping_redirect', 10, 1 );
function my_changed_woocommerce_continue_shopping_redirect( $return_to ){

    $return_to = wc_get_page_permalink( 'checkout' );

    return $return_to;
}


add_filter( 'wc_add_to_cart_message_html', 'my_changed_wc_add_to_cart_message_html', 10, 2 );
function my_changed_wc_add_to_cart_message_html($message, $products){

    if (strpos($message, 'Continue shopping') !== false) {
        $message = str_replace("Continue shopping", "Checkout", $message);
    }

    return $message;

}
Ouzo answered 1/3, 2018 at 21:24 Comment(0)
O
-1

If anyone is interested the following code fixed it perfectly, just replace id-407 with whatever page id your Cart page is:

    /* Remove Continue Shopping Button Add Cart */
body.page-id-407 .woocommerce-message .button {
    display: none
}
Ouzo answered 4/3, 2018 at 0:49 Comment(4)
This doesn't remove anything. It just hides it - an absolutely horrible practice.Tace
This is O.K. for a strictly visual approach as it does hide it from a CSS perspective but the better way is to remove the rendering of the object in the main function loop using an 'add_filter' call which would make for a more performant approach.Statocyst
it better to use these css .woocommerce-cart .wc-forward.button { display:none;} regardless of page id.Sledge
The code used by @Sledge removes the checkout button as well on Storefront, better use .woocommerce-cart .woocommerce-message .wc-forward.button { display:none;}Rostov
I
11

Use preg_replace to find the string containing the full link and return the new message with all the original HTML minus the link.

add_filter('wc_add_to_cart_message_html','remove_continue_shoppping_button',10,2);

function remove_continue_shoppping_button($message, $products) {
    if (strpos($message, 'Continue shopping') !== false) {
        return preg_replace('/<a.*<\/a>/m','', $message);
    } else {
        return $message;
    }
}
Irmgardirmina answered 3/7, 2018 at 20:17 Comment(1)
Do you add this to the functions.php file?Dvina
S
0
/* Start Disable Continue Shopping Message after Add to Cart
*/

add_filter( 'wc_add_to_cart_message', function( $string, $product_id = 0 ) {
    $start = strpos( $string, '<a href=' ) ?: 0;
    $end = strpos( $string, '</a>', $start ) ?: 0;
    return substr( $string, $end ) ?: $string;
});

/* End Disable Continue Shopping Message after Add to Cart
*/
Statocyst answered 27/11, 2018 at 21:45 Comment(0)
P
0

I used this code to disable it all and it works great.

// Remove "Product added to cart" message

add_filter( 'wc_add_to_cart_message_html', '__return_null' );

 

// Remove "Continue Shopping" button

remove_action( 'woocommerce_cart_actions', 'woocommerce_button_continue_shopping', 10 );
Pluto answered 26/7, 2024 at 15:17 Comment(0)
O
-1

If anyone is interested the following code fixed it perfectly, just replace id-407 with whatever page id your Cart page is:

    /* Remove Continue Shopping Button Add Cart */
body.page-id-407 .woocommerce-message .button {
    display: none
}
Ouzo answered 4/3, 2018 at 0:49 Comment(4)
This doesn't remove anything. It just hides it - an absolutely horrible practice.Tace
This is O.K. for a strictly visual approach as it does hide it from a CSS perspective but the better way is to remove the rendering of the object in the main function loop using an 'add_filter' call which would make for a more performant approach.Statocyst
it better to use these css .woocommerce-cart .wc-forward.button { display:none;} regardless of page id.Sledge
The code used by @Sledge removes the checkout button as well on Storefront, better use .woocommerce-cart .woocommerce-message .wc-forward.button { display:none;}Rostov

© 2022 - 2025 — McMap. All rights reserved.