禁用特定产品的 WooCommerce 电子邮件通知 [英] Disable WooCommerce email notification for specific product
问题描述
我可以参考这个功能来禁用电子邮件通知:https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/
I can refer to this function to disable email notification: https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/
但我只想为特定产品禁用它,或者,如果可以更简单,为特定产品类别禁用它.
But I would like to disable it only for a specific product or, if it can be more simple, for a specific product category.
感谢您的帮助
推荐答案
我认为当您尝试从模板中挂钩电子邮件通知时,您可以在其中找到订单,那时电子邮件已经发送.
I think when you try to hook email notification from template, where you can find order, at that time emails are already sent.
您可以尝试一件事 - 使用收件人的钩子,您可以删除收件人电子邮件并返回空字符串.或者如果空字符串触发错误,那么您可以提供一些虚拟电子邮件.
You can try one thing - using recipient's hook you can remove recipient email and return empty string. Or if empty string triggers error, then you can give some dummy email.
为此使用此代码:
// Change new order email recipient for registered customers
function wc_change_admin_new_order_email_recipient( $recipient, $order ) {
global $woocommerce;
// check if product in order
if ( true ) ) {
$recipient = "";
} else {
$recipient = "newbusiness@yourdomain.com";
}
return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);
<小时>
// Change new order email recipient for registered customers
function wc_change_admin_new_order_email_recipient( $recipient, $order ) {
$flagHasProduct = false;
// Get items in order
$items = $order->get_items();
// Loop for all items
foreach ( $items as $item ) {
$product_id = $item['product_id'];
// check if specific product is in order
if ( $product_id == 102 ) {
$flagHasProduct = true;
}
}
// if product is found then remove recipient
if ($flagHasProduct) {
$recipient = "";
} else {
$recipient = "newbusiness@yourdomain.com";
}
return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);
这篇关于禁用特定产品的 WooCommerce 电子邮件通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!