更改特定 WooCommerce 电子邮件通知的发件人姓名和电子邮件地址

Change sender name and email address for specific WooCommerce email notifications

如何在 WooCommerce 中更改特定电子邮件通知的电子邮件发件人地址和姓名?

例如:
仅为客户处理订单电子邮件通知更改发件人姓名和电子邮件地址。

但不是针对所有电子邮件通知,只是针对特定的通知。

发件人姓名和电子邮件地址在这里设置(在 Woocommerce "Emails" 设置选项卡的末尾:

此字段通过专用过滤器挂钩传递,允许您有条件地更改值。

这是一个有条件限制为 "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 = 'jack.the.ripper@freek.com';

    return $from_email;
}, 10, 2 );

代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。

此代码已经过测试并且有效。

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 )