You are here

function uc_select_addresses in Ubercart 8.4

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

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

Parameters

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

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

Return value

array An array of address options.

2 calls to uc_select_addresses()
AddressPaneBase::process in uc_cart/src/Plugin/Ubercart/CheckoutPane/AddressPaneBase.php
Processes a checkout pane.
AddressPaneBase::view in uc_cart/src/Plugin/Ubercart/CheckoutPane/AddressPaneBase.php
Returns the contents of a checkout pane.

File

uc_store/uc_store.module, line 511
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 [];
  }
  $options = [
    -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] = $option;
  }
  $addresses['#options'] = $options;
  return $addresses;
}