Reputation: 570
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'] .= ',[email protected]';
$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 [email protected]. I am using the latest WordPress and woo-commerce plugin.
Please tell me what I did wrong here.
Regards.
Upvotes: 1
Views: 866
Reputation: 254182
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 .= ',[email protected]';
}
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
Upvotes: 2