问题描述
- “Product-title”库存不足。还剩“XX”。
我发现我可以为此使用以下过滤器钩子
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
因此,要使用 WordPress wp_mail() 发送 HTML
格式的电子邮件,请添加这段额外的代码
function filter_wp_mail_content_type() {
return "text/html";
}
add_filter( 'wp_mail_content_type','filter_wp_mail_content_type',0 );