php - Unable to programmatically update WooCommerce "Sent From" address - Stack Overflow

I am attempting to programmatically update the "sent from" address for a particular WooCommer

I am attempting to programmatically update the "sent from" address for a particular WooCommerce email. Specifically the customer_new_account email. I am aware of the woocommerce_email_from_address filter and I am able to (theoretically) update the address using the following:

function custom_send_from_address ( $from_email, $wc_email ) {
    if( $wc_email->id == 'customer_new_account' )
        $from_email = '[email protected]';
    return $from_email;
}
add_filter( 'woocommerce_email_from_address', 'custom_send_from_address', 10, 2 );

However, this only seems to update the "reply to" address, not the "sent from" address. We are using the FluentSMTP plugin, and I have added a connection to this email address to the plugin. I’m not sure if I am missing a step somewhere that would give WordPress access to this email address?

I am attempting to programmatically update the "sent from" address for a particular WooCommerce email. Specifically the customer_new_account email. I am aware of the woocommerce_email_from_address filter and I am able to (theoretically) update the address using the following:

function custom_send_from_address ( $from_email, $wc_email ) {
    if( $wc_email->id == 'customer_new_account' )
        $from_email = '[email protected]';
    return $from_email;
}
add_filter( 'woocommerce_email_from_address', 'custom_send_from_address', 10, 2 );

However, this only seems to update the "reply to" address, not the "sent from" address. We are using the FluentSMTP plugin, and I have added a connection to this email address to the plugin. I’m not sure if I am missing a step somewhere that would give WordPress access to this email address?

Share Improve this question asked Mar 7 at 15:09 brassmookiebrassmookie 2794 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

It is likely that some other plugin or your custom code may be overwriting the from email address. To resolve this try these options:

  1. Look for the plugins or custom code which is hooking to the filter wp_mail_from and check if they are altering your from email address. If yes try to disable them.

  2. Add this filter callback to enable filtering the from email address in FluentSMTP plugin. (This is enabled by default, but just making sure if you have not disabled it in some other place)

    add_filter( 'fluentsmtp_disable_from_name_email', '__return_false', 100 );

  3. Instead of woocommerce_email_from_address filter, use wp_mail_from filter. But the catch here is you will only get the current from email address in the call back. Since you only need to alter the from email address for customer_new_account emails, you need to add_filter before the new customer account email is sent and remove it using remove_filter after the email is sent.

Example:

function custom_send_from_address () {
    return'[email protected]';
}

function attach_filter () {
    // Hook to filter with low priority
    add_filter( 'wp_mail_from', 'custom_send_from_address', 1000 );
}
add_action( 'woocommerce_created_customer_notification', `attach_filter` );

function detach_filter () {
    remove_filter( 'wp_mail_from', 'custom_send_from_address' );
}
add_action( `woocommerce_email_sent`, 'detach_filter' );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744921244a4601144.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信