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;
}
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With