Skip to content
Advertisement

WordPress – add woocommerce billing_phone field into user-new.php and save it into database and my account

I’m facing a problem. I need to create some woocommerce customer role accounts manualy from the wp-admin. What I need to do is to add a woocommerce billing_phone number into the form which will be saved into the database and added to woocommerce my account phone field automatically. I’ve tried to do it with the code bellow but it did not help. Any ideas how could I make it?

I need to add it to user-new.php …I know there is possibility to add the billing_phone after I create the user account, but I want to save time by searching for the account and doing things twice so I want to save time by adding this field directly into the account creation process from wp-admin.

Thank you in advance!

Code I used but did not help:

JavaScript

enter image description here

Advertisement

Answer

This is actually very easy to do. So the way WooCommerce autofills those fields is if by fetching the actually billing and shipping addresses for the user. If we manage so save the users contact number on regster hook we can make this work.

We will first create a field to save mobile data.

JavaScript

Now we would save this mobile in both the fields mobile and billing_mobile.

JavaScript

So to put it all together add the following code in your functions.php file.

JavaScript

This code is tested and it WORKS.

Order Screenshot

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement