How to update user in WordPress

Last Updated:February 23, 2024
// $user = get_user_by('email', $email); 
                    
$user = get_user_by('login', $username); 
 if ($user) {
    // User found
    $user_id = $user->ID; // Get the user ID
    update_user_meta( $user_id, 'billing_phone', $phone );
    update_user_meta( $user_id, 'billing_postcode', $postal );
    update_user_meta( $user_id, 'billing_city', $city );
    update_user_meta( $user_id, 'billing_state', $state );
    echo 'User found with ID: ' . $user_id."<br>";
  } else {
    // User not found
    echo 'User not found.'."<br>";
  }