WooCommerce Notice Messages, how do I edit them?

前端 未结 5 1557
别那么骄傲
别那么骄傲 2021-02-01 05:40

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

5条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 06:16

    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;
    }
    

提交回复
热议问题