WooCommerce - 填写用户个人资料中的名字和姓氏字段 - BUG? [英] WooCommerce - Filling the first and last name fields in the user profile - BUG?

查看:29
本文介绍了WooCommerce - 填写用户个人资料中的名字和姓氏字段 - BUG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在网站上注册(输入用户名和电子邮件)然后去购买,填写发票和运输的详细信息,WordPress用户配置文件中的字段名称为空!

If a user registers on the site (enter username and email) and THEN go to purchase, filling in the details of invoicing and shipping, the field name in the WordPress user profile is empty!

如果客户之前没有注册,而是记录了购买时间,则会填充用户个人资料字段的姓名.

If the customer does not register before, but makes recording the time of purchase, then the name and surname of the user profile fields are populated.

有什么解决办法吗?

谢谢.

查看wordpress用户列表的截图:

See this screenshot of wordpress users list:

推荐答案

我的问题是,由于自定义 woocommerce checkout 和一些混乱的编码,它没有更新用户的 WordPress 名字 &下新订单时的姓氏字段.

My issue was that due to custom woocommerce checkout and little messed up coding, it wasn't updating the user's WordPress first name & last name fields at the time of placing a new order.

我根据我的情况尝试了上面的代码,并稍作调整,但这对我不起作用,因为用户正在创建,然后订单已下达 - 因此在此之前没有关于订单的信息.

I tried the above code with little tweaks based on my scenario but that didn't work for me as the user was getting created and then the order was placed - so there was no information about the order till that time.

我尝试使用类似这样的其他解决方案 - 在结账时将 WooCommerce 的用户名字字段"更新为账单名字",但这对我也不起作用.

I tried hooking other solutions like this - Updating the WooCommerce 'User Firstname Field' with 'Billing First Name' on check out but that didn't work for me either.

或尝试挂钩 process_checkout 但没有任何效果.

or tried to hook process_checkout but nothing worked.

我通过更改 email-order-details.php(woocommerce 的电子邮件模板)解决了这个问题

I solved the issue by making the changes in email-order-details.php (woocommerce's email template)

我在下面添加了以下行:<?php if ( ! $sent_to_admin ) : ?>在第 24 行.

I added the line below after: <?php if ( ! $sent_to_admin ) : ?>on line 24.

<?php wp_update_user( array( 'ID' => (int)$order->user_id, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name) ); ?>

原因:我想在下订单后更改值,并且由于下订单后发送电子邮件,因此添加此内容是有意义的

Reason: I wanted to change the values after the order is placed and since email is sent after the order is placed, it made sense to add this

这篇关于WooCommerce - 填写用户个人资料中的名字和姓氏字段 - BUG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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