Default billing address on checkout form

5 replies [Last post]
Joined: 01/30/2008
Juice: 81

Hi,

Is it possible that the checkout form will populate automaticaly the top saved address?

Customers that'll buy the same product every week will have to make to many clicks...

Thanks

Joined: 08/07/2007
Juice: 15046

You can do this with a custom module using hook_form_alter() or a bit of JS on the checkout page. Altering the form is probably the easiest way to go.

Joined: 01/30/2008
Juice: 81

I hoped it could be the default because I guess everybody will want it.

Thanks

Joined: 08/07/2007
Juice: 15046

Well, as is it's really only one select box for return customers, so I don't think it's asking too much of them. Eye-wink

Joined: 11/19/2007
Juice: 53

I think particularly for retail customers, it makes sense to have the checkbox selected by default. Doesn't it makes sense to add a setting so that individual stores can easily set a default?

Joined: 02/01/2009
Juice: 27

How would I set default of a custom select list? I created a table of branch addresses that I use to populate the select list. I also pull the users' branch from LDAP (profile field). How do I select it as default? The value of the tag contains data of all the fields. Thanks for your help.

<?php
function uc_approval_select_branch($uid, $type = 'billing', $onchange = '', $title = NULL, $icon_suffix = FALSE) {

    global

$user;   
   
$user_info = user_load(array('uid'=>$user->uid));
   
     
$branches = uc_approval_get_branches($uid, $type);

if(!

is_array($branches) || count($branches) == 0) { return NULL; }

 

$options = array('0' => t('Select one...'));
  foreach (
$branches as $branch) {
   
$options[drupal_to_js($branch)] = check_plain($branch['name']);
   
// check if the branch matches
   
if ($branch['name'] == $user_info->profile_branch) {
       
$default = $options[drupal_to_js($branch)];  // set the $default
   
}
  }

 

$select = array(
   
'#type' => 'select',
   
'#title' => is_null($title) ? t('Branches') : $title,
   
'#options' => $options,
   
'#attributes' => array('onchange' => $onchange),
   
'#suffix' => $icon_suffix ? uc_store_get_icon('file:address_book', FALSE, 'address-book-icon') : NULL,
     
'#weight' => -5,
   
'#default_value' => $default// apply the default
 
);

  return

$select;
}
?>

By the way, I tried

<?php
$form
['panes']['delivery']['delivery_branch_select']['#default_value'] = $user_info->profile_branch;
?>

but it did not work.