Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active October 15, 2021 05:24
Show Gist options
  • Save sybrew/ad9ae08724f05c7edb10e780d642cb8d to your computer and use it in GitHub Desktop.
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.
<?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;
} );
@bonniemercer
Copy link

Thanks, worked a like a charm!

@NigelRodgers
Copy link

Thank you, worked!

@mhackersu
Copy link

Works amazingly! Thank you @sybrew

@sonamtsh
Copy link

sonamtsh commented Feb 5, 2019

I am new to this... Where do I insert the above strings? Thank you

@sonamtsh
Copy link

sonamtsh commented Feb 5, 2019

I tried to paste in my theme function php but not working

@IykeBanks
Copy link

IykeBanks commented Feb 9, 2019

@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.

@babakfp
Copy link

babakfp commented Dec 9, 2019

Thanks

@Preciousomonze
Copy link

Preciousomonze commented Aug 3, 2021

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

@joanpla
Copy link

joanpla commented Oct 14, 2021

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