I had this small, annoying problem the other day which is contributing to my hair loss. It was the ability to CC a user into WooCommerce e-mail correspondence. So basically, when WooCommerce sends an e-mail to your customer when their order is placed and completed, I want it to send the email to another user too. That’s all and well if you want to send it to one user for every order, but what I needed was a bit different.
When a customer sets up an account in WooCommerce, they can specify their account login (this is the login / username they use to log into your website), they can also specify a billing e-mail, which would basically mean that any billing related emails, like confirmations from your online shop would go to just the billing e-mail that this customer has provided. That’s fine! BUT – if you for some reason want your user account e-mail and your billing account e-mail to both receive this e-mail, that’s where WooCommerce falls short. I spent hours on end trying to figure out how I can make it work, and I have finally have.
I’m currently running on WooCommerce 2.5.5 (the latest version as of 23rd March 2016), the below code snippet will allow your website to send order confirmation e-mails to both your account user e-mail AND your billing email.
Just add this code snippet into your functions.php
/** * E-mail user and billing e-mail * */ add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 3); function mycustom_headers_filter_function($headers,$object,$order) { global $current_user; get_currentuserinfo(); $headers = array(); if($object == "customer_completed_order"){ $order = new WC_Order($order->id); $customer = get_userdata($order->customer_user); $headers[] = 'cc: '.$customer->display_name.' <'.$customer->user_email .'>'; $headers[] = 'Content-Type: text/html'; return $headers; }else{ $headers[] = 'cc: '.$current_user->user_firstname.' '.$current_user->user_lastname.' <'.$current_user->user_email .'>'; $headers[] = 'Content-Type: text/html'; return $headers; } /*echo 'Username: ' . $current_user->user_login . "\n"; echo 'User email: ' . $current_user->user_email . "\n"; echo 'User level: ' . $current_user->user_level . "\n"; echo 'User first name: ' . $current_user->user_firstname . "\n"; echo 'User last name: ' . $current_user->user_lastname . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; echo 'User ID: ' . $current_user->ID . "\n";*/ }
Depending on your setup, I cannot guarantee that this code will not conflict or work 100%, I take no responsibility for the code, but if it does work,
then you’ve saved yourself some precious coding hours!
Worked perfectly
Thanks for this it works perfectly!
Why is it not included in core Woo Commerce?!!!!