I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register
and profile_update
hooks. This is the simplified code:
function get_all_user_data($user_id) {
$user_data = get_userdata($user_id);
$login = $user_data->user_login;
$b_firstname = get_user_meta($user_id, 'billing_first_name', true);
}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');
The behavior:
- User is registered, I can access it's userdata (e.g. login) immediately
- WooCommerce billing address is updated and saved, however I still only can access the $login variable, 'billing_first_name' meta is apparently still empty at this time
- WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step
The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.
PS: I have also tried the woocommerce_after_save_address_validation
hook, but that seems to have the same behavior as the profile_update
in my case.
Edit: edit_user_profile_update
doesn't work as well. Setting the action priority to a high number (executed later) doesn't help either. insert_user_meta
filter works, but only returns native WP's user meta, not WooCommerce customer's meta.
edit_user_profile_update
here are the documentation: developer.wordpress.org/reference/hooks/… – Ahmad Wael Oct 5 '20 at 21:56profile_update
action from my original solution. The WC customer data is not yet accessible at the time of the action. – Kristián Filo Oct 12 '20 at 6:02