Qubical
Qubical

Reputation: 641

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.

Upvotes: 0

Views: 2122

Answers (1)

Qubical
Qubical

Reputation: 641

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

Upvotes: 1

Related Questions