Skip to content

Instantly share code, notes, and snippets.

@ChromeOrange
Created August 22, 2012 09:08
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ChromeOrange/3423933 to your computer and use it in GitHub Desktop.
Save ChromeOrange/3423933 to your computer and use it in GitHub Desktop.
Custom Add To Cart Messages
<?php
/**
* Custom Add To Cart Messages
* Add this to your theme functions.php file
**/
add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
// Output success messages
if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
$return_to = get_permalink(woocommerce_get_page_id('shop'));
$message = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
else :
$message = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
endif;
return $message;
}
/* Custom Add To Cart Messages */
?>
@fajarvm
Copy link

fajarvm commented Dec 7, 2013

It is really a pity that WooCommerce only passed the $message to the filter hook. Passing the $product_id would be really helpful to allow creative custom message.

@Spreeuw
Copy link

Spreeuw commented Feb 7, 2014

@fajarferdian great suggestion! As per Spreeuw/woocommerce@df773f5 it's included in WC2.1

@Shadowstep33
Copy link

Unfortunately this snippet appears to have stopped working with the latest Woocommerce update (2.1).

@jwebcat
Copy link

jwebcat commented Mar 20, 2014

@Shadowstep33 now its called wc_add_to_cart_message

@lasantha
Copy link

@jwebcat - thank you, helpful I was playing with old hook (woocommerce_add_to_cart_message)

@MarceloPedra
Copy link

Hello guys! Is there any way to redirect the old hook woocommerce_add_to_cart_message to automagically use wc_add_to_cart_message to avoid rewriting entirely old plugins?

@monecchi
Copy link

How about changing the html output of the <a> tag? I need to include an id and a custom data- attribute. E.g id="open_cart" and data-cart="opened" - Manually setting these, just the id is returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment