在 WooCommerce 电子邮件通知中将发件人姓名更改为客户账单全名 [英] Change sender name to customer billing full name in WooCommerce email notifications
问题描述
我如何将电子邮件发件人名称更改为客户先计费&姓氏"使用 woocommerce_email_from_name
钩子?
How can I change E-Mail Sender Name into customer "Billing First & Last Name" using woocommerce_email_from_name
hook?
例如:我的商店"应该改为John Doe".
For Example: "My Shop" should be changed to "John Doe".
基于更改特定 WooCommerce 电子邮件通知的发件人姓名和电子邮件地址 答复代码,这是我的功能:
Based on Change sender name and email address for specific WooCommerce email notifications answer code, here is my function:
add_filter( ‘woocommerce_email_from_name’, function( $from_name, $wc_email ){
if( $wc_email->id == ‘customer_processing_order’ )
// $from_name = ‘Jack the Ripper’;
$from_name = get_user_meta( $user_id, ‘first_name’, true, $user_id, ‘last_name’, true );
//$from_name = get_user_meta( $user_id, ‘first_name’, true );
return $from_name;
}, 10, 2 );
它不起作用.有人可以帮我吗?
ut it doesn't work. Can anyone help me?
推荐答案
以下将更改From name"Woocommerce 电子邮件通知上的客户账单全名:
The following will change the "From name" to customer billing full name on Woocommerce email notifications:
add_filter( 'woocommerce_email_from_name', 'filter_wc_email_from_name', 10, 2 );
function filter_wc_email_from_name( $from_name, $email ){
if( is_a($email->object, 'WC_Order') ) {
$order = $email->object;
$from_name = $order->get_formatted_billing_full_name();
}
return $from_name;
}
代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
附加:对于新订单电子邮件通知,您将使用:
Addition: For "new order email notification, you will use:
add_filter( 'woocommerce_email_from_name', 'filter_wc_email_from_name', 10, 2 );
function filter_wc_email_from_name( $from_name, $email ){
if( $email->id == 'new_order' && is_a($email->object, 'WC_Order') ) {
$order = $email->object;
$from_name = $order->get_formatted_billing_full_name();
}
return $from_name;
}
代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
相关:更改特定 WooCommerce 电子邮件通知的发件人姓名和电子邮件地址
这篇关于在 WooCommerce 电子邮件通知中将发件人姓名更改为客户账单全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!