admin管理员组文章数量:1410697
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 badges1 Answer
Reset to default 1It is likely that some other plugin or your custom code may be overwriting the from email address. To resolve this try these options:
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.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 );
Instead of
woocommerce_email_from_address
filter, usewp_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 forcustomer_new_account
emails, you need toadd_filter
before the new customer account email is sent and remove it usingremove_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' );
本文标签: phpUnable to programmatically update WooCommerce quotSent Fromquot addressStack Overflow
版权声明:本文标题:php - Unable to programmatically update WooCommerce "Sent From" address - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744921244a2632305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论