I'm trying to achieve two way synchronization between user_email and billing_email (the key for woocommerce emails). So far, I have it working that when a customer edits/updates their billing email address their user_email gets updated with the following code:

add_action( 'woocommerce_customer_save_address','isa_customer_save_address', 10, 1);

function isa_customer_save_address() {

global $woocommerce;
$user_id = get_current_user_id();

        wp_update_user( array ( 'ID' => $user_id, 'user_email' =>    $_POST['billing_email'] ) ) ;


Now how do I update a customer's billing_email when they edit/updates their user_email?

  • Hi hazem, what have you tried so far, or are you looking for an advice on how the trigger and action when the user's email changes? – Mark Kaplun Jan 20 '14 at 19:25
  • @MarkKaplun i have edited the question – hazem Jan 20 '14 at 19:44

This code should do it for you. It add an action to the updating of the WordPress profile, checks if the email has been updated, and if so, it updates the Woocommerce address as well.

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

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

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

Edit: I did something wrong here, I'm guessing its pretty basic I just haven't seen it yet.

| improve this answer | |
  • it's not working , i don't know why – hazem Jan 20 '14 at 21:25
  • the problem is , when u say $current_user = wp_get_current_user(); u override the $old_user_data ,so what i mean is both $old_user_data and $current_user hold the same data – hazem Jan 20 '14 at 22:17
  • It's updating the billing_email if the current_email is not equal to the old_user_data. However, I'll do some testing to see if I did something wrong. – hornj Jan 20 '14 at 22:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.