In Woocommerce, I am trying to stop customer order email for a particular product category in woocommerce.
What I have tried is:
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;
}
But this hook is not working at all. Any help is appreciated.
You should try this instead (with
has_term()
WP conditional function):This code goes on function.php file of your active child theme (or theme). Tested and works.
For Others customer order email notification, you will have to add also: