简体   繁体   中英

Send customer invoice email with more recipients for WooCommerce processing orders

On the woocommerce thank you page I want if the order status is processing then send WC_Email_Customer_Invoice email to multiple email addresses.

add_action( 'woocommerce_thankyou', 'dvs_add_more_recipient' );
function dvs_add_more_recipient($order_id) {
    $order = new WC_Order($order_id);
    if( ! $order->has_status( 'processing' ) ) return;
    
    $wc_email = WC()->mailer()->get_emails()['WC_Email_Customer_Invoice'];
    $wc_email->settings['recipient'] .= ',prohostreview@gmail.com';
    $wc_email->trigger( $order_id );            
}

But the issue is email only sent to the customer's email address and there is no email sent to prohostreview@gmail.com. I am using the latest WordPress and woo-commerce plugin.

Please tell me what I did wrong here.

Regards.

Since WooCommerce 3.7 you can use the following instead:

// Trigger email customer invoice for processing orders
add_action( 'woocommerce_order_status_processing', 'send_wc_email_customer_invoice', 10, 2 );
function send_wc_email_customer_invoice( $order_id, $order ) {
    WC()->mailer()->get_emails()['WC_Email_Customer_Invoice']->trigger( $order_id );            
}

// Add recipient to customer invoice for processing orders
add_filter( 'woocommerce_email_recipient_customer_invoice', 'add_recipient_processing_email_customer_invoice', 10, 2 );
function add_recipient_processing_email_customer_invoice( $recipient, $order = false ) {
    if ( ! $order || ! is_a( $order, 'WC_Order' ) ) 
        return $recipient;
        
    if ( $order->get_status() === 'processing' ) {
        $recipient .= ',prohostreview@gmail.com';
    }
    return $recipient;
}

Code goes in functions.php file of the active child theme (or active theme). It should work.

Related: Send customized new order notification only for pending order status and specific payment methods

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