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;
}
Related
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;
}
I am looking to add the shipping address from the order to the New Order email. Can anyone please provide detailed information on how to do so? I am pretty new to editing functions.php, hooks, etc.
Thanks
Use this
you can comment out the conditional part if you want to have it on customer email as well.
add_action( 'woocommerce_email_after_order_table', 'woocommerce_add_shipping_address_to_admin_emails', 15, 2 );
function woocommerce_add_shipping_address_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
echo '<p><strong>Shipping Address:</strong> ' . $order->get_formatted_shipping_address() . '</p>';
}
}
Thank you for this snippet. It works perfectly! Here is a version which separates header (shipping address) from content:
add_action( 'woocommerce_email_after_order_table', 'woocommerce_add_shipping_address_to_admin_emails', 15, 2 );
function woocommerce_add_shipping_address_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
$header = '<p><strong>Shipping Address:</strong> ' . '</p>';
$shippingInfo = '<p>' . $order->get_formatted_shipping_address() . '</p>';
echo $header;
echo $shippingInfo;
}
}
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;
}
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;
}
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;
}