Im trying to create a new user programmatically trough a form but Im having problem with getting the phone numer and country set trough wp_create_user
– why wont it take the values? First and last name works as expected.
Relevant code:
$user_id = wp_create_user( $username, $random_password, $user_email );
wp_update_user([
'ID' => $user_id,
'first_name' => rgar( $entry, '20.3' ),
'last_name' => rgar( $entry, '20.6' ),
'phone' => rgar( $entry, '16' ),
'country' => rgar( $entry, '24.6' )
]);
2
Answers
You can add
country
andphone
as a User meta and save it in the User Meta table:WordPress Codex : Click Here
In with WooCommerce the phone and the country are billing fields so the right user meta keys are:
billing_country
(Remember that you need to set a valid country code)billing_phone
You will also need to set the
billing_email
,billing_first_name
andbilling_last_name
So your code is going to be instead, replacing also your
wp_create_user()
function by:Then to add the WooCommerce user data there is 2 ways:
1). Using
WC_Customer
Object and methods:2) Or using WordPress
update_user_meta()
function (the old way):