На основе " Разные получатели в зависимости от категории продукта в электронном уведомлении WooCommerce " , код ответа, приведенный ниже, позволит добавить другого получателя электронной почты на основе идентификатора продукта:
add_filter( 'woocommerce_email_recipient_new_order', 'custom_email_recipient_new_order', 10, 2 );
function custom_email_recipient_new_order( $recipient, $order ) {
// Not in backend when using $order (avoiding an error)
if( ! is_a($order, 'WC_Order') ) return $recipient;
// Define the email recipients / product Ids pairs
$recipients_product_ids = array(
'product.one@email.com' => array(37),
'product.two@email.com' => array(40),
'product.three@email.com' => array(53, 57),
);
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Loop through defined product categories
foreach ( $recipients_product_ids as $email => $product_ids ) {
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
if( array_intersect([$product_id, $variation_id], $product_ids) && strpos($recipient, $email) === false ) {
$recipient .= ',' . $email;
}
}
}
return $recipient;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы).Проверено и работает.