在WooCommerce中添加缺货电子邮件通知的产品链接 [英] Add product link to out of stock email notification in WooCommerce
本文介绍了在WooCommerce中添加缺货电子邮件通知的产品链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将产品链接放入发送给管理员的脱销电子邮件中。
就我所知,即使我使用了正确的筛选器挂钩,此代码也没有得到预期的结果。有什么建议吗?add_filter('woocommerce_email_content_no_stock', 'add_product_url_to_out_of_stock_email', 10, 2);
function add_product_url_to_out_of_stock_email( $message, $product ) {
global $product; // with or without this is the same result
return $message ."<br>
". get_edit_post_link( $product->get_id() );
}
推荐答案
您可以添加/使用WC_Product::get_permalink()-产品固定链接来自定义$message
以满足您的需要。
因此您得到:
function filter_woocommerce_email_content_no_stock ( $message, $product ) {
// Edit message
$message = sprintf( __( '%s is out of stock.', 'woocommerce' ), '<a href="' . $product->get_permalink() . '">' . html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) . '</a>' );
return $message;
}
add_filter( 'woocommerce_email_content_no_stock', 'filter_woocommerce_email_content_no_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 );
相关:Adding product hyperlink to low stock notification email in WooCommerce
这篇关于在WooCommerce中添加缺货电子邮件通知的产品链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文