0
votes

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);
}
1
Thank you Loic for helping me again..I will surely do more research on the info you gave..Dhaval Chheda
You are welcome. come back later when you are ready and update your question with some code, to get better helped.LoicTheAztec

1 Answers

0
votes

For this thing you can use standard wordpress hook:

// Register subcustomer to same customer

add_action('user_register', 'vmart_add_account_number', 10, 1);

function vmart_add_account_number($user_id)
{
    update_user_meta($user_id, 'account_number', $account_number);
}