-1

I have placed billing information in the checkout pane. I want to autofill the billing information. There is a similar question in stackexchange Autofill billing Information on checkout page in Drupal Commerce. But this is not working for me. This is the code they mentioned

function mymodule_form_alter(&$form, &$form_state, $form_id) { 
  global $user;

  if( $form_id == 'commerce_checkout_form_checkout' && $user->uid ){
    $user = user_load( $user->uid );
    $loaded_billing = commerce_customer_profile_load($user->field_commerce['und'][0]['profile_id']);

    // For each field in customer profile I fill the form field with the $user value 
    $form['customer_profile_billing']['commerce_customer_address']['und'][0]['#address']  = $loaded_billing->commerce_customer_address['und'][0];
    $form['customer_profile_billing']['field_telephone_number']['und'][0]['value']['#default_value']  = $loaded_billing->field_telephone_number['und'][0]['value'];
  } 
}

But I don't have commerce_customer_profile_load($user->field_commerce['und'][0]['profile_id']); . Is there any other solution.

1

Use Commerce Addressbook module which provides solution for your problem. It is already mentioned in the same question as a comment.

More details about this module (from its project page):

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).

Note that for data consistency reasons editing a previously entered address won't change it on previously made orders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy