I am new with Drupal and I am willing to learn more.

now, I am creating a project and I am using the drupal commerce.

In the check-out process, In default, for unregistered users, it has the email field and others field. I just want to add username, password and password confirm fields so that the anonymous user will register then he can pay for the item he cheked-out.

but the problem is I don't know how to add those fields.

I have also checked the Checkout Rules (Create a new account for an anonymous order), I think the process of creating the user is done here, but I don't know how.

Does anyone can help me in my case? any help will be appreciated...

thanks in advance ...

2 Answers 2


This is currently being handled via the Rules module. The rule that is enabled by default creates the user via the "Create a new account for an anonymous order" rule. There is no way to insert a password in here but is up to the user to open the link in their email and set their password manually.


I did it with below solution but I want to create a module for do this is future( If I will hav time :) )

first in my custom module add password field to checkout process

        function yourmodule_form_alter(&$form, &$form_state, $form_id) {
        if ($form['#form_id'] == 'commerce_checkout_form_checkout') {
            global $user;
          if($user->uid==0)  {
          $form['account']['login']['pass'] = array(
          '#type' => 'password_confirm',
          '#title' => t('Password'),
          '#required' => TRUE,
          '#size' => 30,

then save password in session with

        function _myfunction_user_register_incheckout_submit($form,$form_state){
        //    $pass=user_hash_password($form_state['values']['account']['login']['pass']);
        // it's better hash it later , for more security    

        function _ym_session($key, $value = NULL) {
          static $storage;
          if ($value) {
            $storage[$key] = $value ;
            $_SESSION['ym'][$key] = $value ;   // I use 'lists' in case some other module uses 'type' in $_SESSION
          else if (empty($storage[$key]) && isset($_SESSION['ym'][$key])) {
            $storage[$key] = $_SESSION['ym'][$key]?$_SESSION['ym'][$key]:false;
          return $storage[$key];

        function _myfunction_user_register_incheckout($user_account){
        //    ym(user_load($user_account->uid),'message');
        //    ym(user_load($user_account->uid));

after it in commerce_checkout_new_account rules in /admin/config/workflow/rules/reaction/manage/commerce_checkout_new_account add a php action in PHP CODE section add


save it then put it after Fetch entity by property and before 'LOOP' and save rule,

enter image description here

Then test and enjoy it :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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