When the order status in WooCommerce is set from pending to processing I can send an email to my customer. But I need to send an email only to a custom email adresse instead of the customer default address.
Is there a hook or filter for the functions.php file?
This custom function hooked in woocommerce_email_recipient_customer_processing_order filter hook, will do the job (Set in it your replacement email):
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'processing_order_replacement_email_recipient', 10, 2 );
function processing_order_replacement_email_recipient( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
// Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
$recipient = 'name#example.com';
return $recipient;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works
To add the custom recipient to the customer email, you should use this instead (if needed):
$recipient .= ',name#example.com';
Related
So I want to send the same email with a slightly different heading in WooCommerce. It uses the argument $email_heading variable to hold the value of that current email heading so I figure a simple replacement would work. It doesn't. I could be completely missing the mark here any help is much appreciated.
I want it to say Your Order is ready for pickup when they choose local pickup and then the default value (stored the email settings of woocommerce) when any other shipping is chosen.
add_filter( "woocommerce_email_heading_customer_completed_order", 'HDM_woocommerce_email_header', 10, 2 );
function HDM_woocommerce_email_header( $email_heading, $email ) {
if ('customer_completed_order' == $email->id && $order->has_shipping_method('local_pickup') ){
$order_id = $order->get_id();
$email_heading = '<h1>Your Order Is Ready For Pickup</h1>';
}
return $email_heading;
};
There are some mistakes in your code like $email that is in fact $order. Also you are already targeting customer_completed_order in this composite hook, so you don't need it in your IF statement…
So try instead:
add_filter( "woocommerce_email_heading_customer_completed_order", 'custom_email_heading', 10, 2 );
function custom_email_heading( $email_heading, $order ) {
if ( $order->has_shipping_method('local_pickup') ){
$email_heading = '<h1>Your Order Is Ready For Pickup</h1>';
}
return $email_heading;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
i'm wondering if this is valid for email subject:
add_filter( "woocommerce_email_subject_customer_completed_order", 'custom_email_subject', 10, 2 );
function custom_email_subject( $subject, $order ) {
if ( $order->has_shipping_method('local_pickup') ){
$subject = 'Your Order Is Ready For Pickup';
}
return $subject;
}
I'm using Woocommerce and the Product Addons plugin to add extra fields to a product. One of those fields is an email address to let people send the confirmation of the order to a DIFFERENT address than the billing address shown on the checkout page. Emails should be sent to both addresses.
Any thoughts on maybe how to modify the functions.php file to do this?
In the woocommerce_email_recipient_{$this->id} filter hook, you can use the $order argument to get your 2nd email.
But first Lets add globally an email field with the Product Add-ons plugin…
The add on field on the product (fill the field and add to cart):
This "Email" field in order-received (Thank you) page, after checkout:
As you can notice the label of this field is "Email"…
Now if I look in the database in wp_woocommerce_order_itemmeta for this order I can see for the meta_key "Email" the meta_value "loic#TheAztec.com" :
Now I can set the correct meta_key in the code below to get my email.
Here is the code that will add this additional email recipient for processing and completed customer order email notifications:
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'additional_customer_email_recipient', 10, 2 ); // Processing Order
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'additional_customer_email_recipient', 10, 2 ); // Completed Order
function additional_customer_email_recipient( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;
$additional_recipients = array(); // Initializing…
// Iterating though each order item
foreach( $order->get_items() as $item_id => $item_data ){
// HERE set the the correct meta_key (like 'Email') to get the correct value
$email = wc_get_order_item_meta( $item_id, 'Email', true );
// Avoiding duplicates (if many items with many emails)
// or an existing email in the recipient
if( ! in_array( $email, $additional_recipients ) && strpos( $recipient, $email ) === false )
$additional_recipients[] = $email;
}
// Convert the array in a coma separated string
$additional_recipients = implode( ',', $additional_recipients);
// If an additional recipient exist, we add it
if( count($additional_recipients) > 0)
$recipient .= ','.$additional_recipients;
return $recipient;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works.
You can add below code in your function.php
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2);
function your_email_recipient_filter_function($recipient, $object) {
$recipient = $recipient . ', me#myemail.com';
return $recipient;
}
and if you want to send email in BCC then please try below code:
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function( $headers, $object ) {
if ($object == 'customer_completed_order') {
$headers .= 'BCC: My name <my#email.com>' . "\r\n";
}
How to change email sender address and name in WooCommerce for specific email notifications?
For example:
Change the sender name and email address just for customer processing order email notifications.
But not for all email notifications, just for specific ones.
The sender name and email address are set here (at the end of Woocommerce "Emails" setting tab:
This fields are passed through dedicated filters hook that allow you to change conditionally the values.
Here is an example conditionally restricted to "customer processing email notification":
// Change sender name
add_filter( 'woocommerce_email_from_name', function( $from_name, $wc_email ){
if( $wc_email->id == 'customer_processing_order' )
$from_name = 'Jack the Ripper';
return $from_name;
}, 10, 2 );
// Change sender adress
add_filter( 'woocommerce_email_from_address', function( $from_email, $wc_email ){
if( $wc_email->id == 'customer_processing_order' )
$from_email = 'jack.the.ripper#freek.com';
return $from_email;
}, 10, 2 );
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.
Some other WC_Email Ids that you can use in your condition:
- 'customer_completed_order'
- 'customer_on_hold_order'
- 'customer_refunded_order'
- 'customer_new_account'
- 'new_order' ( admin notification )
- 'cancelled_order' ( admin notification )
- 'failed_order' ( admin notification )
As title mentioned, is there any possible way to add email notification just like email to customer on cancelled order.
I would like to email to notice on cancelled order due to time limit of pending payment.
Any possible way??
Here is a custom hooked function in woocommerce_email_recipient_cancelled_order filter hook:
add_filter( 'woocommerce_email_recipient_cancelled_order', 'adding_customer_email_recipient_to_cancelled', 10, 2 );
function adding_customer_email_recipient_to_cancelled( $recipient, $order ){
if( is_admin() ) return $recipient;
$billing_email = $order->get_billing_email();
$recipient .= ', ' . $billing_email;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works on WooCommerce 3.0+
You can use action hook woocommerce_order_status_cancelled, this action is executed when order status is changed to cancelled.
In example:
add_action('woocommerce_order_status_cancelled', function($order_id){
//send email here
}, 10, 1);
I am very new to WordPress, and have created an e-commerce store with WooCommerce.
After the customer places an order, I get an email and the customer get an email- one for me to say what they have ordered, and one to them as a thank you email.
Within this thank you email, in my functions.php file, I have learned to change the subject of the header to include their name such as this:
//add the first name of the person to the person getting the reciept in the subject of the email.
add_filter('woocommerce_email_subject_customer_processing_order','UEBC_change_processing_email_subject', 10, 2);
function UEBC_change_processing_email_subject( $subject, $order ) {
global $woocommerce;
$subject = 'Thanks for your ' . get_bloginfo( 'name', 'display' ) . ' Order, '.$order->billing_first_name .'!';
return $subject;
}
The code snippet above works correctly, and is only displayed to the customer, not to me. e.g. "thanks for your order ABCD Clothes order John!".
Within the body of the email, I am trying to make this personal as a small thank you message, however, when I make the message, I am using the hook:
add_action( 'woocommerce_email_before_order_table', 'custom_add_content', 20,1 );
I know that since im using the woocommerce_email_before_order_table hook, the custom function will be send in the body of the email to both the customer and myself.
I was wondering, is there a hook that Woocommerce provides so that the custom function will only be sent to the customer within the body of the email?
For example: woocommerce_email_header_customer_processing_order or words to that effect?
Thanks
To add some custom content using woocommerce_email_before_order_table hook and targeting just the customer "processing order" email notification, you should try this:
add_action( 'woocommerce_email_before_order_table', 'custom_content_to_processing_customer_email', 10, 4 );
function custom_content_to_processing_customer_email( $order, $sent_to_admin, $plain_text, $email ) {
if( 'customer_processing_order' == $email->id ){
// Set here as you want your custom content (for customers and email notification related to processing orders only)
echo '<p class="some-class">Here goes your custom content… </p>';
}
}
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
This code is tested and works