Reputation: 2463
I need to know WooCommerce new order email to given email address for only in specific products.
Ex: if any body buy a product X need a new order email to Y. The Y is not set in as back end Recipient. Is there any hook to achieve this ?
I tried follow
add_action( 'woocommerce_order_status_completed', 'custom_woocommerce_order_status_completed' );
function custom_woocommerce_order_status_completed( $order_id ) {
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($items as $key => $value) {
if($value == 10) { // given product id
// trigger order complete email for specific email address
}
}
}
Upvotes: 2
Views: 2484
Reputation: 923
You can put the following in your functions.php:
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);
function your_email_recipient_filter_function($recipient, $object) {
$recipient = $recipient . ', [email protected]';
return $recipient;
}
the only drawback is that the recipient will see both your address & his own in the To: field.
Alternatively, you can use the woocommerce_email_headers filter. the $object passed allows you to only apply this to the completed order email:
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function( $headers, $object ) {
if ($object == 'customer_completed_order') {
$headers .= 'BCC: My name <[email protected]>' . "\r\n";
}
return $headers;
}
Taken from this answer from Ewout.
Upvotes: 3