1

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 = 'constantmail@gmail.com';
    $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
    ) );
}
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Pickeroll
  • 908
  • 2
  • 10
  • 25

1 Answers1

2

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 = 'constantmail@gmail.com';

    // 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.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Thanks for your reply. But in this way the mail will be he same, I was hoping to make some customization to the mail for the second subject. – Pickeroll Oct 12 '20 at 12:31