I am working on a woocommerce project and my requirement is that whenever a new user registration occurs there should an account number generated which should be mailed to him so I am trying to use the update_user_meta function but not understanding how to get the User_id for somebody who has not yet registered
Please check my code and advise
add_action('woocommerce_register_form', 'vmart_add_account_number');
function vmart_add_account_number() {
global $wpdb;
$userdata = array();
$user_id = wp_insert_user($userdata);
$account_number = 1;
update_user_meta($user_id, 'account_number', $account_number);
$account_number++;
}
I have also tried this code
add_action('user_register', 'vmart_add_account_number', 10, 1);
function vmart_add_account_number($user_id)
{
$accountnumber = 1;
update_user_meta($user_id, 'account_number', $accountnumber);
}