Last active
October 15, 2021 05:24
-
-
Save sybrew/ad9ae08724f05c7edb10e780d642cb8d to your computer and use it in GitHub Desktop.
Removes "Continue Shopping" message from WooCommerce after item has been added to cart.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
\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; | |
} ); |
I am new to this... Where do I insert the above strings? Thank you
I tried to paste in my theme function php but not working
@sonamtsh it should work. Paste it in your theme's function.php file. I just tried it and it worked. It should be the last line of code. That's where I pasted mine. Don't copy the opening php tag. Copy from 2nd line and the rest of code.
Thanks
Thanks for this @sybrew , to avoid deprecated notices, use wc_add_to_cart_message_html
.
wc_add_to_cart_message
has been deprecated as of 3.0 i think 🤔.
More info here : https://stackoverflow.com/a/55738046/5510038
Thanks. Here's the updated snippet (credit to mayersdesign from Stackoverflow):
//remove message CONTINUE SHOPPING after an item has been added to cart
function filter_wc_add_to_cart_message_html( $message, $products ) {
return "<span>".$message."</span>";
};
add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works amazingly! Thank you @sybrew