简体   繁体   中英

Send processing email notification to an additional hidden recipient in WooCommerce

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
    ) );
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM