Woocommerce new order additional email recipient added in order meta

I'm trying to add an additional recipient to the customer order confirmation email.

I have added a meta value for the additional recipients email address into the order successfully and have hooked into some of the emails, however, I am finding it tricky to find the hook for the conformation email.

My code:

add_filter('woocommerce_email_recipient_customer_processing_order', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_completed_order', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_invoice', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_invoice_paid', 'ddl_additional_email_checkout', 10, 2);
add_filter('woocommerce_email_recipient_customer_note', 'ddl_additional_email_checkout', 10, 2);
function ddl_additional_email_checkout($emails, $object){
    
    $additional_email = get_post_meta($object->id, 'additional_recipient', true);
    
    if( $additional_email ){
        $emails .= ',' . $additional_email;
    }

    return $emails;

}

Ideally I'd hook into something like woocommerce_email_recipient_customer_new_order but that does not appear to be an option.

Many thanks.

Solutions

The first comment linking to https://stackoverflow.com/a/61459068/11987538 solved this for me, in essence it was simply find the correct $email_id

This piece of code also was very helpful in that it will display the ID in the email.

add_action( 'woocommerce_email_order_details', 'add_custom_text_to_new_order_email', 10, 4 );
function add_custom_text_to_new_order_email( $order, $sent_to_admin, $plain_text, $email ) {
    // Only for "New Order"  email notifications (to be replaced by yours)
    if( ! ( 'new_order' == $email->id ) ) return;

    // Display a custom text (for example)
    echo '<p>'.__('My custom text').'</p>';
}

From Targeting specific email with the email id in Woocommerce

Similar questions

How to change the email notification recipient (user) for new comments?
How do you change the user that gets the notification email announcement for new comments and comment moderation? WordPress sends the notices to the admin user. My client is the editor of the site. I want the comment notices to get mailed to the editor user and not the admin user. How do you do that?
WP/Woo send email to custom meta recipient while post is being published
I want to send an email after a new woo product is published. The recipient email is being added inside a custom meta in the product. Below is what I have in my functions.php so far. If I add a manual email in the function it works but unfortunately I can't get the post meta. Is this because the function is being triggered while the product is bein...
Change WooCommerce email recipient depending on address - Woocommerce Local Pick up Plus
I'm using Woocommerce Local Pick up Plus and want to change the email address depending on the order_shipping_method, but I can't get it work and I can't use var_dump to see whats happening
How to get WooCommerce email recipient?
How to get recipient of the woocommerce emails for $wc_recipient var in this code?
How to detect email recipient in Woocommerce template partial?
I'm trying to customize email templates in woocommerce so the customer gets the normal email notification with his new order data with some little customization, and the admin gets the new order email notification with some more detailed data of the order. Woocommerce provides several email templates and hooks to customize this, and in fact, there'...
Unable to use WooCommerce custom field as recipient in custom email
What I'm trying to accomplish is to use custom fields from my checkout in a new custom email. I've found documentation on returning the key, value within the body of the email and in order details, which works. The problem is I can't get this to work with a new custom order notification, where I want to use 'back-up email' as the recipient of the c...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.