Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change sender name and email address for specific WooCommerce email notifications

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.

like image 457
Nikola Avatar asked Sep 08 '17 13:09

Nikola


People also ask

How do I change the sender name in WooCommerce?

Navigate to WooCommerce -> Settings -> Emails and change Email Sender Options.

How do I add custom email notifications in WooCommerce?

To set up the email, you'll need to go to WooCommerce > Settings > Emails. From here, you can click on any of the default WooCommerce emails to edit them, or click Add New Email to create a custom email. When creating or editing an email, you'll be able to enter a Subject, and the Body of the email.

How do I fix email notifications in WooCommerce?

It's possible that you've inadvertently disabled your emails from sending. To check, in the WordPress dashboard go to WooCommerce > Settings > Emails and for each of your transactional emails, click “Manage” and check that the “Enable this email notification” box is ticked before you save changes.


1 Answers

The sender name and email address are set here (at the end of Woocommerce "Emails" setting tab:

enter image description here

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 = '[email protected]';

    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 )

like image 169
LoicTheAztec Avatar answered Sep 30 '22 07:09

LoicTheAztec