Drupal Commerce assign role on account create on checkout When a checkout is completed by an anonymous user on a Drupal Commerce website, a Drupal account will be created. I would look to auto-assign a role like 'customer' to the newly created Commerce user. How can I do that programmatically? It has to be in Drupal 7 code so I can use it for my custom module.
$account = new stdClass;
$account-&gt;is_new = TRUE; //indicate the account is new
$account-&gt;name = 'account_name';
$account-&gt;pass = user_hash_password('password'); // make a function to create random passwords
$account-&gt;mail = 'email';
$account-&gt;init = 'email';
$account-&gt;status = TRUE; //set the user to activated at creation
$account-&gt;roles = array(DRUPAL_AUTHENTICATED_RID =&gt; TRUE); //set user as authenticated user
$account-&gt;timezone = variable_get('date_default_timezone', '');
$new_user = user_save($account); //create user (user_save() returns a fully loaded $user object)


$role_name = 'ROLE_NAME'; // The name of the role to add.
if ($role = user_role_load_by_name($role_name)) {
  user_multiple_role_edit(array($new_user-&gt;uid), 'add_role', $role-&gt;rid);
}


You can use the hook: hook_user_insert. 
And apply the last piece of code from above to update the role.