Adding product hyperlink to low stock notification email in WooCommerce(将产品超链接添加到WooCommerce中的低库存通知电子邮件)
本文介绍了将产品超链接添加到WooCommerce中的低库存通知电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
默认情况下,库存不足通知电子邮件包含此文本。
- &Q;产品-标题&Q;库存不足。剩下&Q;XX&Q;。
我想编辑此邮件,以便将产品超链接添加到产品标题。
我发现我可以为此使用以下筛选器挂钩
add_filter( 'woocommerce_email_content_low_stock', 'low_stock_dspixel', 10, 2 );
function low_stock_dspixel( $message, $product ) {
$message = sprintf(/* translators: 1: product name 2: items in stock */
__( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
html_entity_decode( wp_strip_all_tags( $product->get_stock_quantity() ) )
);
return $message;
}
如何进一步调整此链接以添加产品超链接?
推荐答案
您可以添加/使用WC_Product::get_permalink()-产品固定链接来自定义$message
以满足您的需要。
因此您得到:
function filter_woocommerce_email_content_low_stock ( $message, $product ) {
// Edit message
$message = sprintf(
/* translators: 1: product name 2: items in stock */
__( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
'<a href="' . $product->get_permalink() . '">' . html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) . '</a>',
html_entity_decode( wp_strip_all_tags( $product->get_stock_quantity() ) )
);
return $message;
}
add_filter( 'woocommerce_email_content_low_stock', 'filter_woocommerce_email_content_low_stock', 10, 2 );
重要提示:此答案默认不起作用,因为wp_mail()用作邮件功能,其中内容类型为text/plain
,不允许使用HTML
因此,要使用WordPresswp_mail()发送HTML
格式化的电子邮件,请添加此额外代码
function filter_wp_mail_content_type() {
return "text/html";
}
add_filter( 'wp_mail_content_type', 'filter_wp_mail_content_type', 10, 0 );
相关:Add product link to out of stock email notification in WooCommerce
这篇关于将产品超链接添加到WooCommerce中的低库存通知电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:将产品超链接添加到WooCommerce中的低库存通知电子邮件


猜你喜欢
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01