-1

How to send "admin new order e-mail" additionally in cc to office@mydomain.com when new order has products from category id = "99" ?

Can anyone help me?

Nero
  • 41
  • 3

1 Answers1

0

I guess something like this should do the trick:

 add_filter( 'woocommerce_email_headers','stack_overflow_add_cc_to_new_order_email',10,4 );

function stack_overflow_add_cc_to_new_order_email( $header, $mail_id, $mail_obj, $wc_email ) {
    if ( $mail_id == "new_order" ) {
        $header .= "Cc: Name <your@email.com>" . "\r\n"; // del if not needed
    }
    
    return $header;
}

The explanation is simple, everytime a WC email is sent the woocommerce_email_headers is called. Inside that filter you gain access to the "id" of the email (the way wc distinguish the emails) so you can check if it's the new_order email and if so add the corrisponding header to the email.

I didn't test the code but it should work. Place that code inside your theme function.php file

Diego
  • 1,610
  • 1
  • 14
  • 26
  • Sorry, but dont work: Uncaught ArgumentCountError: Too few arguments to function stack_overflow_add_cc_to_new_order_email() – Nero Sep 01 '20 at 06:50
  • ops sorry, updated the answer. Should work now. Was missing the 2 more parameters for add_filter which are priority and number of arguments. Since the custom function has 4 parameters you have to add "10,4" where 10 is the default priority and 4 is the magic number – Diego Sep 01 '20 at 09:50
  • @Nero does that work for you with the new update? if yes, accept the answer please – Diego Sep 02 '20 at 07:24