You are here

function uc_select_address in Ubercart 5

Same name and namespace in other branches
  1. 8.4 uc_store/uc_store.module \uc_select_address()
  2. 6.2 uc_store/uc_store.module \uc_select_address()
  3. 7.3 uc_store/uc_store.module \uc_select_address()

Create 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'.

3 calls to uc_select_address()
uc_checkout_pane_billing in uc_cart/uc_cart_checkout_pane.inc
Get the billing information.
uc_checkout_pane_delivery in uc_cart/uc_cart_checkout_pane.inc
Get the delivery information.
uc_order_address_book_form in uc_order/uc_order.module

File

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

Code

function uc_select_address($uid, $type = 'billing', $onchange = '', $title = NULL, $icon_suffix = FALSE) {
  $addresses = uc_get_addresses($uid, $type);
  if (!is_array($addresses) || count($addresses) == 0) {
    return NULL;
  }
  $options = array(
    '0' => t('Select one...'),
  );
  foreach ($addresses as $address) {
    $options[drupal_to_js($address)] = check_plain($address['street1']);
  }
  $select = array(
    '#type' => 'select',
    '#title' => is_null($title) ? t('Address book') : $title,
    '#options' => $options,
    '#attributes' => array(
      'onchange' => $onchange,
    ),
    '#suffix' => $icon_suffix ? uc_store_get_icon('file:address_book', FALSE, 'address-book-icon') : NULL,
  );
  return $select;
}