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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0