0

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.

Qubical
  • 641
  • 5
  • 13
  • You can set up the filter hook based on the $email_id: `woocommerce_email_recipient_{$email_id}`, for the right/possible `$email_id` view https://stackoverflow.com/a/61459068/11987538 or https://stackoverflow.com/a/47742782/11987538. So it looks like you're looking for `new_order`. **Also see** second part from [this answer](https://stackoverflow.com/a/68220362/11987538) – 7uc1f3r Aug 27 '21 at 11:10
  • $order->get_id() – Howard E Aug 27 '21 at 11:13
  • Perfect, the first link in the first comment put me on track. Many thanks to @7uc1f3r and Howard E for you kind help. – Qubical Aug 27 '21 at 14:57

1 Answers1

1

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

Qubical
  • 641
  • 5
  • 13