WooCommerce BCC on complete order mail to customer - wordpress

When someone makes an order in woocommerce, he gets also an email when the order is complete. I'd like to add additional recipients for this email. However! I'd only like this extra BCC to be made on these exact mails. Not all the other mails going through.
It's something like this, but then with the correct filter / name: add_bcc_to_wc....
add_filter( 'woocommerce_email_headers', 'add_bcc_to_wc_admin_new_order', 10, 3 );
function add_bcc_to_wc_admin_new_order( $headers = '', $id = '', $wc_email = array() ) {
if ( $id == 'new_order' ) {
$headers .= "Bcc: my_personal#email.com\r\n"; // replace my_personal#email.com with your email
}
return $headers;
}
With kind regards,
Dennis

Add bcc e-mail to customer order confirmation
add_filter( 'woocommerce_email_headers', 'firefog_headers_filter_function', 10, 2);
function firefog_headers_filter_function( $headers, $object ) {
if ($object == 'new_order') {
$headers .= 'BCC: NAME <name#domain.com>' . "\r\n";
}
return $headers;
}

Related

Add a Supplier custom field email address as BCC to woocommerce email New Order

I have a holiday letting wordpress site which has the advanced custom field "Supplier Email" in the add listing page. When a rental is booked the Supplier Email needs to be added to the woocommerce New Order email under BCC, i have tried numerous options but they have not worked, the Supplier Email is in the post meta so it needs to be pulled in to the new order email. This is the code i have in my functions.php file:
add_filter( 'woocommerce_email_headers', 'bcc_to_email_headers', 10, 3 );
function bcc_to_email_headers( $headers, $email_id, $order ) {
if ( $email_id === 'new_order' ) {
$supplier_email = get_field( 'supplier_email_main',$post_id);
if ( $supplier_email ) {
$headers .= "CC: Supplier <" . $supplier_email . ">\r\n";
$headers .= "BCC: New Order <myemail#gmail.com>" . "\r\n";
}
}
return $headers;
}
The gmail address(this would go to my personal email, have hidden it here for obvious reasons) i added to BCC didnt even get sent. Not sure how to proceed with this, any help would be greatly appreciated, please note i am not a wordpress developer. Thanks in advance.
try this
add_filter( 'woocommerce_email_headers', 'add_bcc_header', 10, 3 );
function add_bcc_header( $headers, $id, $order ) {
if ( $id == 'new_order' ) {
$headers .= 'Bcc: gmailaddress#gmail.com' . "\r\n";
}
return $headers;
}

Wordpress/Woo add headers BCC on custom email template

I have gift cards plugin that is sending a custom email template to the user. How do I manipulate that email header in my functions.php file and add a BCC based on a custom order meta? That order meta has an email address in the value.
add_filter( 'woocommerce_email_headers', 'order_completed_email_add_bcc', 9999, 15 );
function order_completed_email_add_bcc( $headers, $email, $order ) {
if ( 'pw_gift_card' == $email ) {
$bcc = get_post_meta( $order->id, 'my_custom_order_meta', true );
$headers .= "Bcc: ".$bcc."" . "\r\n";
}
return $headers;
}
Your code seem to be alright although it needs improvement. You have 3 arguments and not 15. Also for brevity, use $order->get_meta() instead of get_post_meta().
add_filter( 'woocommerce_email_headers', 'order_completed_email_add_bcc', 9999, 3 );
function order_completed_email_add_bcc( $headers, $email_id, $order ) {
if ( 'pw_gift_card' == $email_id && $bcc = $order->get_meta('my_custom_order_meta')) {
$headers .= 'Bcc: ' . $bcc . '\r\n';
}
return $headers;
}

Woocommerce: Use Email address from Custom field as recipient completed order/invoice

I created a custom field in Woocommerce for a second customer email address:
purchase_order_email
Now I need Woocommerce to use that email adres to send invoices to as wel as the standard customer email address.
Hope you can help.
I'm using Woocommerce PDF invoices & Packing Slips plugin for invoices.
Just found this code which should work but gave a fatal error: A non expected 'if'.
add_filter( 'woocommerce_email_headers', 'wcpdf_email_cc_alternative',
10, 3);
function wcpdf_email_cc_alternative( $headers, $email_id, $order ) {
if ($email_id == 'customer_completed_order') {
$alternative_email = get_post_meta( $order->id,
'purchase_order_email', true)
if ( $alternative_email ) {
$headers .= 'CC: ' . $alternative_email . "\r\n"; //just repeat
this line again to insert another email address in BCC
}
}
return $headers;
}
Thanks in advance!
EDIT
Found a solution
Code needed to be adjusted to (was missing a semicolon and get_post_meta needed to be changed to get_meta):
add_filter( 'woocommerce_email_headers', 'wcpdf_email_cc_alternative',
10, 3);
function wcpdf_email_cc_alternative( $headers, $email_id, $order ) {
if ($email_id == 'customer_completed_order') {
$alternative_email = $order->get_meta( 'purchase_order_email', true
);
if ( $alternative_email ) {
$headers .= 'CC: ' . $alternative_email . "\r\n"; //just repeat
this line again to insert another email address in BCC
}
}
return $headers;
}

Woocommerce - Bcc email only when the admin is recipient OR by Order Status

How to Get email recipient to make an conditional function to add extra bcc email header on email only to admin OR by Order Status?
add_filter( 'woocommerce_email_headers', 'profit_extra_email', 10, 2);
function profit_extra_email( $headers ) {
$headers .= 'BCC: Vendas Promocional Fitness <eu#site.com>' . "\r\n";
return $headers;
}
This function above work, but bcc email retrieve all emails. I need retrieve only emails to admin OR by Order Status.
Help any!! :O
There are 3 variables passed to the woocommerce_email_headers filter. Since none of them appear to be the $in_admin variable that is passed to templates, we have to take a different approach. The second param is $email_id which is a unique identifier for each email class. Therefore we can make an array of all the admin emails and check if the current email is in that array. If so, add your CC.
function so_31737121_email_headers( $headers, $email_id, $order ){
$admin_emails = array(
'low_stock',
'no_stock',
'backorder',
'cancelled_order',
'new_order'
);
if( in_array( $email_id, $admin_emails ) ){
$headers .= 'BCC: Vendas Promocional Fitness <eu#site.com>' . "\r\n";
}
return $headers;
}
add_action( 'woocommerce_email_headers', 'so_31737121_email_headers', 10, 3 );

Additional recipients on woocommerce invoice

Is there way to add additional recipients to woocommerce invoice mail.
I have tried to use 'woocommerce_email_headers' hook, but it's not working:
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function($headers, $object) {
$headers = array();
$headers[] = 'Bcc: My Name <me#gmail.com>';
$headers[] = 'Content-Type: text/html';
return $headers;
}
Any advice?
You can expand the function to include the order as well:
add_filter( 'woocommerce_email_headers', 'woo_cc_emails', 10, 3 );
function woo_cc_emails( $headers, $status, $object ) {
return 'Bcc: your#email.here' . "\r\n";
}
Some months later, but I hope this will help someone.
add_filter('woocommerce_email_headers', 'woo_cc_emails');
function woo_cc_emails() {
return 'Bcc: your#email.here' . "\r\n";
}
You can change "Bcc", with "To" or "Cc".
I needed help to add a BCC to a New Customer Account email. Here is what I came up with. It's slightly different than above. Hope this helps someone.
add_filter( 'woocommerce_email_headers', 'add_bcc_to_wc_customer_new_account', 10, 3 );
function add_bcc_to_wc_customer_new_account( $headers = '', $id = '', $wc_email = array() ) {
if ( $id == 'customer_new_account' ) {
$headers .= "Bcc: my_personal#email.com\r\n"; // replace my_personal#email.com with your email
}
return $headers;
}

Resources