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();
$old_user_data
echo the old email , which means that current_user object override the $old_user_data object , how to solve this ?