Save user fields in commerce profile I add some fields to default user fields,like  phone,address,city,... , I want If user edit or filled up his user information in user/uid/edit when submit ,if there is not any commerce shipping profile, create a profile to him/her, and if there is , update default shipping profile ,
how can I achieve this job?
I know I can create  profile with something like below code

 $new_profile = commerce_customer_profile_new($type);
  $wrapper = entity_metadata_wrapper('commerce_customer_profile', $new_profile);
  $wrapper-&gt;uid = $account;
  $wrapper-&gt;commerce_customer_address-&gt;country = $country;
  $wrapper-&gt;commerce_customer_address-&gt;name_line = $name_line;
  $wrapper-&gt;commerce_customer_address-&gt;first_name = $first_name;
  $wrapper-&gt;commerce_customer_address-&gt;last_name = $last_name;
  $wrapper-&gt;commerce_customer_address-&gt;organisation_name = $organisation;
  $wrapper-&gt;commerce_customer_address-&gt;administrative_area = $administrative_area;
  $wrapper-&gt;commerce_customer_address-&gt;sub_administrative_area = $sub_administrative_area;
  $wrapper-&gt;commerce_customer_address-&gt;locality = $locality;
  $wrapper-&gt;commerce_customer_address-&gt;dependent_locality = $dependent_locality;
  $wrapper-&gt;commerce_customer_address-&gt;postal_code = $postal_code;
  $wrapper-&gt;commerce_customer_address-&gt;thoroughfare = $thoroughfare;
  $wrapper-&gt;commerce_customer_address-&gt;premise = $premise;
  $wrapper-&gt;field_bcg_customer_phone = $phone;
  commerce_customer_profile_save($new_profile);


but my question is , how can set it as default, after user edited (updated) if there is default profile , update it also

appreciate any help
As you mention you're looking for setting the profile as default, I'm assuming you're using Commerce Addressbook or in any case looking for a very similar feature of what that module provides.


  Commerce Addressbook is a module that allows authenticated customers to reuse
  previously entered addresses during checkout.
  They can manage all entered addresses in their user panel (user/%user/addressbook).


You can use commerce_addressbook_set_default_profile function to set the default (one per type). Example:

$billing_profile = commerce_customer_profile_new('billing', $user-&gt;uid);
  $billing_profile-&gt;commerce_customer_address[LANGUAGE_NONE][0]['name_line'] = 'Sample Customer';
  $billing_profile-&gt;commerce_customer_address[LANGUAGE_NONE][0]['country'] = 'US';
  $billing_profile-&gt;commerce_customer_address[LANGUAGE_NONE][0]['thoroughfare'] = '16 Hampton Ct';
  $billing_profile-&gt;commerce_customer_address[LANGUAGE_NONE][0]['locality'] = 'Visalia';
  $billing_profile-&gt;commerce_customer_address[LANGUAGE_NONE][0]['administrative_area'] = 'CA';
  $billing_profile-&gt;commerce_customer_address[LANGUAGE_NONE][0]['postal_code'] = '93277-8329';
  commerce_customer_profile_save($billing_profile);
  commerce_addressbook_set_default_profile($billing_profile);


I'd recommend another way to create the profile, for example:

    // Create the new profile now.
    $profile = commerce_customer_profile_new('billing', $order-&gt;uid);

    // Add the address value.
    $profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);

    $profile_wrapper-&gt;commerce_customer_address = array_merge(addressfield_default_values(), array(
      'country' =&gt; $country, 
      'name_line' =&gt; $name . ' ' . $last_name, 
      'first_name' =&gt; $first_name, 
      'last_name' =&gt; $last_name,
    ));

    // Save the profile.
    $profile_wrapper-&gt;save();