Update WordPress User Email, Name in Sync with WooCommerce Account

When a customer edits/updates their billing email address, or billing name, through the WooCommerce “edit billing details” section, this function will also automatically update their WordPress email address and/or name.

This code snippet is over a year old, from before WooCommerce 2.0. I don’t know if this function works with WooCommerce 2.0+.
**  update WordPress user email, first and last name when customer edit's billing email address on woocommerce account

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'] ) ) ;
			wp_update_user( array ( 'ID' => $user_id, 'first_name' => $_POST['billing_first_name'] ) ) ;
			wp_update_user( array ( 'ID' => $user_id, 'last_name' => $_POST['billing_last_name'] ) ) ;


See more:


We've 8 Responses

  1. June 9th, 2013 at 5:00 pm

    hmm i don’t think it does work 🙁 but i am searching across the internet to just make this function work:

    function please_work() {
    global $woocommerce;
     $user_id = get_current_user_id();
    $post_save = get_post_meta( $user_id, '_last_name', true );
    echo $post_save;

    My aim is echo the current guest or logged in user saved last name on the product page. This user made a order already, so the saved meta data from the checkout page, I would like to use.

  2. December 9th, 2015 at 4:00 pm

    Works one way (profile get updated with billinng infos), but cans it goes both ways? Is the billing name and last name can be sync with the profile?

    • July 2nd, 2016 at 1:07 pm

      Yes, can be sync.

      add_filter( 'profile_update' , 'custom_update_checkout_fields', 10, 2 );
      function custom_update_checkout_fields($user_id, $old_user_data ) {
        $current_user = wp_get_current_user();
        // Updating Billing info
        if($current_user->user_firstname != $current_user->billing_first_name)
          update_user_meta($user_id, 'billing_first_name', $current_user->user_firstname);
        if($current_user->user_lastname != $current_user->billing_last_name)
          update_user_meta($user_id, 'billing_last_name', $current_user->user_lastname);
        if($current_user->user_email != $current_user->billing_email)
          update_user_meta($user_id, 'billing_email', $current_user->user_email);
  3. June 28th, 2017 at 11:10 am

    But billing name is part of the address and the user could have multiple addresses, so how does this work when having multiple billing addresses with different names?


Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: