Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 避免在Woocommerce中针对特定产品类别发送客户电子邮件通知_Php_Wordpress_Woocommerce_Orders_Email Notifications - Fatal编程技术网

Php 避免在Woocommerce中针对特定产品类别发送客户电子邮件通知

Php 避免在Woocommerce中针对特定产品类别发送客户电子邮件通知,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,在Woocommerce中,我试图阻止客户针对Woocommerce中特定产品类别的订单电子邮件 我尝试的是: add_filter('woocommerce_email_recipient_customer_processing_order', 'wc_change_customer_new_order_email_recipient', 10, 3); function wc_change_customer_new_order_email_recipient( $recipient, $or

在Woocommerce中,我试图阻止客户针对Woocommerce中特定产品类别的订单电子邮件

我尝试的是:

add_filter('woocommerce_email_recipient_customer_processing_order', 'wc_change_customer_new_order_email_recipient', 10, 3);
function wc_change_customer_new_order_email_recipient( $recipient, $order ) {
 global $woocommerce;
    $items = $order->get_items();
    $category_ids = array( 10 );
    $flagHasProduct = false;
    foreach ( $items as $item ) {
        $product_id = $item['product_id'];
        $terms = get_the_terms( $product_id, 'product_cat' ); 

        foreach ( $terms as $term ) {  
            if( in_array( $term->term_id, $category_ids ) ) {
                $flagHasProduct = true;
            }
        }

    }
    if ($flagHasProduct) {
        $recipient = "";
    } 
    $recipient = "";
    return $recipient;
}

但这个钩子根本不起作用。非常感谢您的帮助。

您应该尝试以下方法(使用
has_term()
WP条件函数):

此代码位于活动子主题(或主题)的function.php文件中。测试和工作

这将避免仅客户“处理”订单电子邮件通知

对于其他客户订单电子邮件通知,您还必须添加:

// Customer "completed" Order email notification
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "on-hold" Order email notification
add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "refunded" Order email notification
add_filter( 'woocommerce_email_recipient_customer_refunded_order', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "invoice" email notification
add_filter( 'woocommerce_email_recipient_customer_invoice', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "completed" Order email notification
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "on-hold" Order email notification
add_filter( 'woocommerce_email_recipient_customer_on_hold_order', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "refunded" Order email notification
add_filter( 'woocommerce_email_recipient_customer_refunded_order', 'product_cat_avoid_processing_email_notification', 10, 2 );

// Customer "invoice" email notification
add_filter( 'woocommerce_email_recipient_customer_invoice', 'product_cat_avoid_processing_email_notification', 10, 2 );