简体   繁体   English

Wordpress-新用户通知电子邮件包含名称

[英]Wordpress - New User Notification Email Include Name

I've modified the New User Notification Email to include address details entered during the shopping cart of WooCommerce, but I also need to include the first and last name. 我已经修改了“新用户通知电子邮件”,以包括在WooCommerce购物车中输入的地址详细信息,但我还需要包括名字和姓氏。

The following code will print the last name matching the hard coded ID... 以下代码将打印与硬编码ID相匹配的姓氏...

$user_last = get_user_meta( 5952, 'last_name', true );
$message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

Why does the following not print the last name matching the new users ID? 为什么以下内容不打印与新用户ID匹配的姓氏?

$user_last = get_user_meta( $user_id, 'last_name', true );
$message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

The following prints the correct ID that I'm trying to target, so this makes little sense to me... 下面的代码显示了我要定位的正确ID,因此这对我来说意义不大...

$message .= sprintf(__('User ID: %s'), $user_id) . "\r\n\r\n";

If anyone has any suggestions, I'd be very grateful. 如果有人有任何建议,我将不胜感激。

Use the user properties to get first and last name. 使用用户属性获取名字和姓氏。

First Name: $user->first_name 名:$ user-> first_name

Last Name: $user->last_name 姓氏:$ user-> last_name

If that doesn't work go in and check the user has a first and last name set. 如果这样不起作用,请进入并检查用户是否设置了名字和姓氏。

Example: 例:

printf( "Full Name: %s %s", $user->first_name, $user->last_name );

Or for your question replace: 或为您的问题替换:

$message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

With: 带有:

$message .= sprintf(__('Last Name: %s'), $user->last_name) . "\r\n\r\n";

I used the following code... 我用下面的代码...

$firstname = $_POST['billing_first_name'];
$lastname = $_POST['billing_last_name'];

$message .= sprintf(__('First Name: %s'), $firstname) . "\r\n\r\n";
$message .= sprintf(__('Last Name: %s'), $lastname) . "\r\n\r\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM