Send processing email notification to an additional hidden recipient in WooCommerce

570 views Asked by At

I'm trying to send an extra mail using the customer-processing-order.php template, so when a User received the mail with the order details, another subject will receive a similar mail.

This is my trying, but when I click on the submit order button the program freeze in a loading page.

function email_processing_notification( $order_id ) {

    $order = wc_get_order( $order_id );

    // load the mailer class
    $mailer = WC()->mailer();

    $recipient = '[email protected]';
    $subject = __('Some Subject', 'test');
    $content = get_processing_notification_content( $order, $subject, $mailer );
    $headers = "Content-Type: text/html\r\n";

    $mailer->send( $recipient, $subject, $content, $headers );

}

add_action( 'woocommerce_email_order_details', 'email_processing_notification', 10, 1 );


function get_processing_notification_content( $order, $heading = false, $mailer ) {

    $template = 'emails/customer-processing-order.php';

    return wc_get_template_html( $template, array(
        'order'         => $order,
        'email_heading' => $heading,
        'sent_to_admin' => true,
        'plain_text'    => false,
        'email'         => $mailer
    ) );
}
1

There are 1 answers

1
LoicTheAztec On

You should better add the additional email address as Bcc using (for processing email notification):

add_filter( 'woocommerce_email_headers', 'custom_cc_email_headers', 10, 3 );
function custom_cc_email_headers( $header, $email_id, $order ) {

    // Only for "Customer Processing Order" email notification
    if( 'customer_processing_order' !== $email_id )
        return $header;

    $email = '[email protected]';

    // Add email address as Cc to headers
    $header .= 'Bcc: '.$email .'\r\n';

    return $header;
}

Code goes in function.php file of your active child theme (or active theme). It should works.

This way is much more simpler and the additional email address will be hidden from customer.