を更新することができますwp_update_user使用私はこの問題は、$user = wp_insert_user($userdata);
は任意のデータを挿入しないことであると思いますが、ちょうど$user
変数にそれを保存し、あなたのコード内の後、あなたはもうそれを使用しないでください。
set_shipping_city();
もセッションデータ関数であり、既存の顧客セッションまたはカートセッション(WC_cart)を使用する必要があります。
だから私は少しあなたのコードを変更しました:
$userdata = array (
'user_login' => $email,
'user_email' => $email,
'user_pass' => $password,
'first_name' => $first_name,
'last_name' => $last_name
) ;
$user_id = wp_insert_user($userdata) ;
// Here you insert your user data with a 'customer' user role
wp_update_user(array ('ID' => $user_id, 'role' => 'customer')) ;
//Once customer user is inserted/created, you can retrieve his ID
global $current_user;
$user = wp_get_current_user();
$user_id = $user->ID;
// or use instead: $user_id = get_current_user_id();
// Checking if user Id exist
if(!empty($user_id)) {
// You will need also to add this billing meta data
update_user_meta($user_id, 'billing_first_name', $first_name);
update_user_meta($user_id, 'billing_last_name', $last_name);
update_user_meta($user_id, 'billing_email', $email);
// optionally shipping meta data, that could be different
update_user_meta($user_id, 'shipping_first_name', $first_name);
update_user_meta($user_id, 'shipping_last_name', $last_name);
update_user_meta($user_id, 'shipping_email', $email);
// Now you can insert the required billing and shipping city
update_user_meta($user_id, 'billing_city', 'Bangalore');
// optionally shipping_city can be different…
update_user_meta($user_id, 'shipping_city', 'Bangalore');
} else {
// echo 'User Id doesn't exist';
}
次にあなたがkeys
で任意のアドレスのデータを挿入するupdate_user_meta()
機能を使用することができます。
billing_first_name
billing_last_name
billing_company
billing_email
billing_phone
billing_address_1
billing_address_2
billing_country
billing_state
billing_postcode
shipping_first_name
shipping_last_name
shipping_company
shipping_email
shipping_phone
shipping_address_1
shipping_address_2
shipping_country
shipping_state
shipping_postcode
参考: