mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/75581685/disable-order-completed-woocommerce-mail-to-customers-for-specific-products
19 lines
789 B
Text
19 lines
789 B
Text
function filter_woocommerce_email_recipient_new_order( $recipient, $order ) {
|
|
// Avoiding backend displayed error in WooCommerce email settings
|
|
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
|
|
|
|
// Loop through order items
|
|
foreach ( $order->get_items() as $key => $item ) {
|
|
// Product ID
|
|
$product_id = $item->get_variation_id() > 0 ? $item->get_variation_id() : $item->get_product_id();
|
|
|
|
// Product ID occurs and count is equal to 1
|
|
if ( in_array( $product_id, array( 111 ) ) && count( $order->get_items() ) == 1 ) {
|
|
$recipient = '';
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $recipient;
|
|
}
|
|
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'filter_woocommerce_email_recipient_new_order', 10, 3 );
|