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->uid = $account;
$wrapper->commerce_customer_address->country = $country;
$wrapper->commerce_customer_address->name_line = $name_line;
$wrapper->commerce_customer_address->first_name = $first_name;
$wrapper->commerce_customer_address->last_name = $last_name;
$wrapper->commerce_customer_address->organisation_name = $organisation;
$wrapper->commerce_customer_address->administrative_area = $administrative_area;
$wrapper->commerce_customer_address->sub_administrative_area = $sub_administrative_area;
$wrapper->commerce_customer_address->locality = $locality;
$wrapper->commerce_customer_address->dependent_locality = $dependent_locality;
$wrapper->commerce_customer_address->postal_code = $postal_code;
$wrapper->commerce_customer_address->thoroughfare = $thoroughfare;
$wrapper->commerce_customer_address->premise = $premise;
$wrapper->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