禁用WooCommerce电子邮件通知我可以参照此功能禁用电子邮件通知: https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/针对特定产品
但我想禁用它仅适用于特定的产品,或者,如果它可以更简单,对于一个具体的产品类别。
感谢您的帮助
禁用WooCommerce电子邮件通知我可以参照此功能禁用电子邮件通知: https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/针对特定产品
但我想禁用它仅适用于特定的产品,或者,如果它可以更简单,对于一个具体的产品类别。
感谢您的帮助
我认为当你尝试从模板,在那里你可以找到订单,当时的电子邮件已经发出已勾电子邮件通知。
您可以尝试一件事 - 使用收件人的挂钩,您可以删除收件人电子邮件并返回空字符串。或者,如果空字符串触发错误,那么你可以给一些虚拟电子邮件。
使用此代码如下:
// 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 = "[email protected]";
}
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 = "[email protected]";
}
return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);
感谢@ vidish-purohit的帮助!
这里,如果你需要禁用管理电子邮件通知针对特定产品我的代码使用方法:
function change_email_recipient_depending_of_product_id($recipient, $order) {
global $woocommerce;
$items = $order->get_items();
foreach ($items as $item) {
$product_id = $item['product_id'];
if ($product_id == xxx) {
$recipient = '';
}
return $recipient;
}
}
add_filter('woocommerce_email_recipient_new_order', 'change_email_recipient_depending_of_product_id', 10, 2);
如果你需要禁用客户电子邮件通知特定产品:
function change_email_recipient_depending_of_product_id($recipient, $order) {
global $woocommerce;
$items = $order->get_items();
foreach ($items as $item) {
$product_id = $item['product_id'];
if ($product_id == xxx) {
$recipient = '';
}
return $recipient;
}
}
add_filter('woocommerce_email_recipient_customer_processing_order', 'change_email_recipient_depending_of_product_id', 10, 2);
感谢您的帮助!是的,它可以是一个解决方案,删除收件人的电子邮件,有趣的...现在困难的部分是写条件(如果产品ID是...)。 – jjj
如果您看到函数参数,那么您将获得order对象作为第二个参数。您可以从中获得所有物品,并检查特定产品是否在订单中。让我知道你是否仍然需要帮助。 –
谢谢Vidish,如果我们认为产品ID是102,代码的外观如何,是的,我们将不胜感激。 – jjj