How to change sender email in WooCommerce?

WooCommerce -> Settings -> EmailS ->

the first two parameters "FROM: Name, FROM: Email"

are the email address and the sender's name. When an order is placed, an email notification is sent to both the store manager and the Customer from the same email and sender name (which we set from the admin control panel).

When Customer

replying to this email, it basically replies to Shop Manager

, and it works great.

But Shop Manager

receives an email notification from his (given) email address, it will actually be the customer's email.

PS: I want the Store Manager to receive an email from the customer billing email and the customer receives it from the Store Manager via email.

https://wordpress.org/plugins/woocommerce/

+3


source to share


3 answers


The only thing I can think of to achieve this is to programmatically generate a Shop Manager notification message 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 outgoing messages.

So, 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 system code included at runtime) that could generate this programmatic email when, for example, a new order is generated.



Hope it helps.

+1


source


After going through your question, it made sense that for the store owner, it should feel like mail had to be sent from an address as the customer's email address so that he could respond to every order in a single email stream.

//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 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 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 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 can result in a message and warning when viewing the message on your side, only "If this message was not sent to: (your client billing address) , as it actually is not that sent by the client to you.

Try the above code and lemme will know if it works for you and fulfills your goals.

+1


source


I think you can also use Wordpress intercept for this:

// 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' );

      

0


source







All Articles