WooCommerce -> Settings -> EmailS -> the first two options, "FROM: Name, FROM: Email", are the Sender's email and name. When an order is placed a notification email is sent to both Shop Manager and Customer from the same Sender's email and name (which we set from admin dashboard).
When Customer replies to that email, he basically replies to Shop Manager and it works fine.
But Shop Manager receives the notification email from his (given) email address, in actually there would be client's email.
P.S: I want that Shop Manager gets the email from the customer's billing email and customer gets it from Shop Manager's given email.
https://wordpress.org/plugins/woocommerce/
The only way I can think of to achieve this is to programmatically generate the Shop Manager notification email using one of the system action hooks. Since there is only one field in the "from" settings, it will be used (by default) for all the outbound messages.
That said, check out the Code Snippets plugin at https://wordpress.org/plugins/code-snippets/. You can put some code here (and it will be saved to the DB, and included the system code at runtime) that could generate this programmatic email when, say, a new order is generated.
Hope it helps.
After going through your question it made sense that for a shop owner it needs to be like the mail should have sent from address as the client's email address, so that he can reply to each order in a single email thread.
//filter for the "mail from" email address which is set in WooCommerce Settings Email Tab-> Email Sender Options -> "From" Email Address which is generally set to the shop admin email address or a support team email address.
add_filter('wp_mail_from', 'wdm_sent_from_email', 99, 1);
//function which will change the mail from email address to the the Customer's billing address if the mail this filter is running which sending mail to the admin.
function wdm_sent_from_email( $sent_from = '' ) {
//check whether our custom parameter is set or not.
if ( isset($_POST['wdm_sent_to_admin']) ) {
//check whether the mail is sent to the admin and other recieptent other than customer
if ( $_POST['wdm_sent_to_admin'] ) {
//set it to the customer's billing email
$sent_from = $_POST['billing_email'];
//set this parameter back to false
$_POST['wdm_sent_to_admin'] == false;
}
}
return $sent_from;
}
//filter for email from name
add_filter('wp_mail_from_name', 'wdm_sent_from_name', 99, 1);
function wdm_sent_from_name( $sent_from_name = '' ) {
//check whether our custom parameter is set or not.
if ( isset($_POST['wdm_sent_to_admin_from_name']) ) {
//check whether the mail is sent to the admin and other recieptent other than customer
if ( $_POST['wdm_sent_to_admin_from_name'] ) {
//set sent mail from name eg. "Website-Name customer"
$sent_from_name = wp_specialchars_decode(esc_html(get_option('woocommerce_email_from_name')), ENT_QUOTES) . " customer";
//set this parameter back to false
$_POST['wdm_sent_to_admin_from_name'] = false;
}
}
return $sent_from_name;
}
//action were we will set and the parameter to indicate whether the mail is sent to admin or customers.
add_action('woocommerce_email_header', 'wdm_header_function', 99, 1);
function wdm_header_function( $email_heading ) {
if ( $email_heading == 'New customer order' ) {
//parameter to indicate whether to change the from email in the mail.
$_POST['wdm_sent_to_admin'] = true;
//parameter to indicate whether to change the from name in the mail.
$_POST['wdm_sent_to_admin_from_name'] = true;
//Just to indicate in mail sent to admin that the sent from email is set in code.
echo "<b>Its Because you have chosen to have this email sent from Customer's Email id.</b>";
} else {
//parameter to indicate whether to change the from email in the mail.
$_POST['wdm_sent_to_admin'] = false;
//parameter to indicate whether to change the from name in the mail.
$_POST['wdm_sent_to_admin_from_name'] = false;
}
}
Note : This might give you and alert message while viewing the message at your side only saying "This message may not have been sent by: (your customer's billing address) " as this is not really sent by a customer to you.
Try out the above code and lemme know whether it works for you and accomplishes your purpose.
I think you can also use wordpress hooks for that:
// Function to change email address
function wpb_sender_email( $original_email_address ) {
return 'tim.smith#example.com';
}
// Function to change sender name
function wpb_sender_name( $original_email_from ) {
return 'Tim Smith';
}
// Hooking up our functions to WordPress filters
add_filter( 'wp_mail_from', 'wpb_sender_email' );
add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
Related
I need WooCommerce to send specific emails from the customer's email address rather than the admin email address.
Background:
I'm setting up a paid support service which uses WooCommerce for payments and bbPress as a ticketing system.
A user orders a service product through WooCommerce and a new WooCommerce order is created. The order needs to then populate a ticketing system and my workaround is to have the 'New order' email sent to an email inbox and then pulled in by the ticketing system. Obviously this is not perfect and introduces a point of failure but it's fine for now.
The problem is that the new order email is sent from the WooCommerce admin email address, so the new ticket is associated with that account rather than the account of the user who created the order.
So I need the email from address to be the address of the user that submitted the order.
Is this possible with a hook?
in woocommerce/includes/class-wc-emails.php we have the following:
public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = '' ) {
// Send.
$email = new WC_Email();
return $email->send( $to, $subject, $message, $headers, $attachments );
}
This doesn't include the sender, and as it's buried in a class, could it be overridden anyway?
Greatful for any pointers.
(PS I do appreciate there are issues with this approach, including emails being flagged as spam, but initially this will be manageable until I get a more robust system in place)
(PPS I'm aware there is an almost identical question but the links aren't working and relates to a very out of date WooCommerce)
That's impossible to send the email from your customer email address. You can only set the customer email to Reply-To in WP_Mail header.
In my experience, you should send another email to your sepcific email inbox, and skip the email sent by WooCommerce by default. Use this hook:
add_action('woocommerce_order_status_pending_to_processing', 'order_created_send_email');
function order_created_send_email($order_id, $order) {
$customer_email = $order->get_billing_email();
/* Code to send email with Reply-To: customer email */
}
I want to send e-mails to user account email and not to billing email in WooCommerce.
I only found that code but I think this is outdated and I also don't want to send 2 mails only one to customer user email.
Code here:
https://www.webdesign101.net/send-e-mails-user-account-email-billing-email-woocommerce/
Tried this code but outdated and also 2 mails instead of one going to user email.
And I didn't found the line in woocommerce/templates/email to change the header from billing_email to user_email.
I want so send emails from WooCommerce to user email not to billing email.
function wc_change_new_order_email_recipient($recipient, $order) {
global $woocommerce;
$user = $order->get_user();
$recipient[] = $user->user_email;
return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_new_order_email_recipient', 10, 2);
I'm looking for a solution where we can disable woocommerce sending email notification when an order is done by a client from a specific customer group (user role).
I found answer about a situation what prevent sending email for a specific product-ID.
Disable WooCommerce email notification for specific product.
Maybe this could be possible for our 'problem' too?
Kind regards,
Kees
You can use the hook for any email and inside the callback function you can check if the user has a specific role
function change_new_order_email_recipient( $recipient, $order ) {
global $woocommerce;
$uid = $order->get_user_id();
$user_meta=get_userdata($uid);
$user_roles=$user_meta->roles;
if(in_array('customer', $user_roles)){ // Prevent email if user role is customer
$recipient ='';
}
return $recipient;
}
add_filter('woocommerce_email_recipient_customer_completed_order', 'change_new_order_email_recipient', 1, 2);
I have checked the code rapidly and is working
Is it possible to have different "FROM" / sender email addresses for the different outgoing email types in woocommerce?
For example;
Processing, Complete, Order on hold, refunded to come from orders#domain.com email address
Reset password, New accounts to come from accounts#domain.com
I can only see the option to have ALL emails sent from the same email address that is put in the "FROM" email field but would like to be able to have different FROM/sender emails for different types of email?
Late, I know... But, from what I can tell, there's no existing solution and it's certainly not an option that comes default with WooCommerce.
You can set the sender manually for each email ID you can check against with a conditional.
For example, when an email is sent, check if it is "whatever email" and if so, mail sender is "abc#abc.abc". This would be relatively straight forward with WooCommerce emails, but I'm not too sure of all the internal WP emails and whether there's something you can check against for them.
Here's how you would do it in WC (from this post) - Add this to your functions.php or a custom plugin.
// 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 );
I’m just after some coding help with a Woocommerce tweak a client needs on their Wordpress site. We have a Woocommerce site that has just been set up as an enquiry system. When the customer places an order, the client gets a normal New Order notification by email.
However, we need the format of that email to be modified so that when the client get that email, they can reply to their customer's email address, not their own site's email address that was set in Woocommerce. (As it is normally, they would have to either forward it or copy/paste the contents of that email into a fresh email and put in the customers email address manually in order to respond.) They don’t want to have to do that.
How can I achieve this
many thanks in advance!
cheers,
Kurt
I had the same problem and managed to get this done by following this two tutorials:
http://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
http://web.peterhartree.co.uk/2014/woocommerce-change-reply-field/
Hopefully this helps.
Regards, Christian
The following snippet will only you to update the reply-to header for the New Order email:
add_filter('woocommerce_email_header', 'spigot_reply_to_mail_filter', 11, 3);
function spigot_reply_to_mail_filter($headers = '', $ordertype = 'new_order', $order = '') {
if(!is_object($order) || empty($order) || $ordertype !== 'new_order') { return $headers; }
$name = $order->get_billing_first_name().' '.$order->get_billing_last_name();
$email = $order->get_billing_email();
if(is_array($headers)) {
$headers['Reply-To'] = "{$name} <{$email}>";
} else {
$headers .= "Reply-To: {$name} <{$email}>\r\n";
}
return $headers;
}
credit goes to: https://spigotdesign.com/change-woocommerce-new-order-reply-address-customer/