WooCommerce Notice Messages, how do I edit them?

Majo0od picture Majo0od · Oct 4, 2014 · Viewed 78.6k times · Source

I'm trying to figure out where WooCommerce creates it's messages for when there is a success, error or notice in WooCommerce. I want to edit those messages to fit the scenario more neatly and also edit the HTML. Where are these messages located and how do I edit them?

Answer

Yavor picture Yavor · Oct 9, 2014

Many of them are directly in the plugin files - unfortunately. Some messages are tied to filter hooks that allow you to edit them without messing with plugin files but that's not always the case.

The message you wanted to change was "Product Name was successfully added to your cart". This one is set in the function wc_add_to_cart_message in wc-cart-functions.php and this function allows you to change it using a filter:

wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );

So in your functions.php file you could add something like:

add_filter('wc_add_to_cart_message', 'handler_function_name', 10, 2);
function handler_function_name($message, $product_id) {
    return "Thank you for adding product" . $product_id;
}