更改特定 WooCommerce 电子邮件通知的发件人姓名和电子邮件地址 [英] Change sender name and email address for specific WooCommerce email notifications

查看:68
本文介绍了更改特定 WooCommerce 电子邮件通知的发件人姓名和电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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

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

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 = 'jack.the.ripper@freek.com';

    return $from_email;
}, 10, 2 );

代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

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.

您可以在您的条件下使用的其他一些 WC_Email Id:- 'customer_completed_order'
- 'customer_on_hold_order'
- 'customer_refunded_order'
- 'customer_new_account'
- 'new_order' (管理员通知)
- 'cancelled_order' (管理员通知)
- 'failed_order' (管理员通知)

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 )

这篇关于更改特定 WooCommerce 电子邮件通知的发件人姓名和电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆