WooCommerce 添加到购物车消息通知文本 [英] WooCommerce added to cart message notification text
问题描述
我一整天都在努力弄清楚如何将 HTML 内容添加到 WooCommerce添加到购物车"通知消息中.默认情况下,它只显示纯文本.
仅供参考 - 实际文本已在 WooCommerce .po 文件中翻译,如下所示:
I've been struggling all day to figure out how to add HTML content to the WooCommerce "added to cart" notification message. Per default it just displays plain text.
FYI - the actual text is translated in the WooCommerce .po file, to look like this:
<h5>added</h5><strong>%s</strong> has been added to your basket.
我想出使用下面的代码片段将输出转换为 HTML,但我不知道如何将它添加到子主题 functions.php
I have figured out to use the below snippet to convert the output to HTML, but I cannot figure out how to add it to the child theme functions.php
$message .= "Content-Type: text/html; charset=UTF-8\r\n";
我可以在这种情况下使用它,但更喜欢从 .po 文件中提取文本:
I am able to use it in this context, but would prefer to just pull the text from the .po file:
add_filter( 'wc_add_to_cart_message_html', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
$message .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<h5>added</h5>Product has been added to your basket.' ;
return $message;
}
我的 php 知识处于最低限度,我非常感谢有关如何实现基本 html 更改代码 - add_filter/add_action 或类似内容的一些反馈.
My php knowledge is at a bare minimum and I would really appreciate some feedback on how to implement the basic html changing code - add_filter / add_action or something similar.
推荐答案
你可以试试下面的代码:
You can try code below:
function custom_add_to_cart_message() {
$return_to = get_permalink(wc_get_page_id('shop'));
if (get_option('woocommerce_cart_redirect_after_add')=='yes') {
$message = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(wc_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
} else {
$message = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping →', 'woocommerce'), __('Product successfully <h5>added</h5>to your cart.', 'woocommerce') );
}
return $message;
}
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
我检查过它对我来说工作正常.希望能帮到你.
I checked it's work fine for me. Hope help you.
这篇关于WooCommerce 添加到购物车消息通知文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!