I am trying to add additional email recipient based on payment method Id on WooCommerce "New order" email notification.
Here is my code:
function at_conditional_admin_email_recipient($recipient, $order){
// if( ! is_a($order, 'WC_Order') ) return $recipient;
if ( get_post_meta($order->id, '_payment_method', true) == 'my_custom_gateway_id' ) {
$recipient .= ', [email protected]';
} else {
$recipient .= ', [email protected]';
}
return $recipient;
};
add_filter( 'woocommerce_email_recipient_new_order', 'at_conditional_admin_email_recipient', 10, 2 );
But the hook doesn't seem firing my function. What could be the reason?
Your code is outdated since Woocommerce 3, try the following instead:
Code goes in functions.php file of your active child theme (or active theme). It should works.