You are here

function uc_select_addresses in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_store/uc_store.module \uc_select_addresses()

Creates an address select box based on a user's previous orders.

Parameters

$uid: The user's ID to search for in the orders table.

$type: Choose either 'shipping' or 'billing'.

1 call to uc_select_addresses()
uc_checkout_pane_address in uc_cart/uc_cart_checkout_pane.inc
Generic address pane handler.

File

uc_store/uc_store.module, line 1493
Contains global Ubercart functions and store administration functionality.

Code

function uc_select_addresses($uid, $type = 'billing') {
  $addresses = uc_get_addresses($uid, $type);
  if (empty($addresses)) {
    return array();
  }
  $options = array(
    -1 => t('Select one...'),
  );
  foreach ($addresses as $key => $address) {
    $option = $address['street1'];

    // Check if the address is a duplicate (i.e. same address, but sent to
    // different person).
    if (isset($addresses[$key - 1]) && $option == $addresses[$key - 1]['street1'] || isset($addresses[$key + 1]) && $option == $addresses[$key + 1]['street1']) {
      $option .= ' - ' . $address['first_name'] . ' ' . $address['last_name'];
    }
    $options[$key] = check_plain($option);
  }
  $addresses['#options'] = $options;
  return $addresses;
}