iam trying to update woocommerce billing_email when user_email is updated , the problem is how to hold two objects from wp_user within the same action , in this code

add_action('profile_update', 'sync_woocommerce_email', 10, 2) ;

function sync_woocommerce_email( $user_id, $old_user_data ) {
$current_user = wp_get_current_user();

    echo $current_user->user_email;
    echo $old_user_data->user_email."   ";

if ($current_user->user_email != $old_user_data->user_email) {
    wp_update_user( array ( 'ID' => $current_user->ID, 'billing_email' => $current_user->user_email ) ) ;

when i do this two echo i found the same email twice , but when i remove

 $current_user = wp_get_current_user();


echo the old email , which means that current_user object override the $old_user_data object , how to solve this ?


I was frustrated by the same thing in WordPress. Check out my unanswered question: Content hooks vs User hooks

I ended up getting around it by matching the user id and updating all the user fields regardless of whether they were updated.

Until WordPress treats users' hooks the same as posts' hooks I think we're stuck with subpar processes.

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.