禁用特定产品的WooCommerce电子邮件通知 [英] Disable WooCommerce email notification for specific product

查看:54
本文介绍了禁用特定产品的WooCommerce电子邮件通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以参考此功能禁用电子邮件通知: 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆