WooCommerce 通知消息,我如何编辑它们? [英] WooCommerce Notice Messages, how do I edit them?
问题描述
我试图找出 WooCommerce 在哪里创建它的消息,以便在 WooCommerce 中出现成功、错误或通知.我想编辑这些消息以更巧妙地适应场景并编辑 HTML.这些消息位于何处以及如何编辑它们?
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?
推荐答案
其中许多直接在插件文件中 - 不幸的是.某些消息与过滤器挂钩相关联,允许您编辑它们而不会弄乱插件文件,但情况并非总是如此.
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.
您想要更改的消息是产品名称已成功添加到您的购物车".这是在 wc-cart-functions.php 的 wc_add_to_cart_message 函数中设置的,该函数允许您使用过滤器更改它:
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 ) );
所以在你的functions.php文件中你可以添加如下内容:
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;
}
这篇关于WooCommerce 通知消息,我如何编辑它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!