1

I have multisite running with 4 sites. One of them has woocommerce. Customers have option to create account while checkout. I have custom analytics where registered customers are labeled with wordpress user ID (get_current_user_id()). Customers without account have default ID of 0. My analytics allow me to add first name, last name, email etc... to customer according to his ID. I would like to add this information right after they make account. I used user_register hook to do this job but it is not working.

Here is my code in themes functions.php (for simplicity I am not adding analytics code)

function update_user($customer){

    $first_name = get_user_meta($customer, 'first_name', true);
    $last_name = get_user_meta($customer, 'last_name', true);

}

add_action( 'user_register', 'update_user' );

Here I am trying to save first and last name in variables which are later passed to analytics however I am not getting any result. Maybe I do not fully understand documentation or I do not know the right way to do it.

Or would you suggest any other method of getting users information after their registration?

Please could you help me?

Thank you in advance.

1

So user_register is when the post data for user registration is submitted. Can you try this

if ( isset( $_POST['first_name'] ) ) {
    $first_name = $_POST['first_name'];
}

Ditto for last_name.

I looked up the codex for the user_register hook, check the example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.