function uc_addresses_get_address_format in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 uc_addresses.module \uc_addresses_get_address_format()
Returns address format for specific country.
First is checked if there is an Ubercart Addresses specific address format. This country format can be set at: admin/store/settings/countries/edit/uc_addresses_formats
When there is no Ubercart Addresses address format found, the address format defined by Ubercart core will be taken and this format will be converted to an Ubercart Addresses address format before it's returned.
If there is also no Ubercart core address format found, a default address format will be returned.
Parameters
int $country_id: The ID of the country to retrieve the address format for.
Return value
string An address format consisting of tokens.
2 calls to uc_addresses_get_address_format()
- uc_addresses_country_formats_form in ./
uc_addresses.admin.inc - Form for address format.
- uc_addresses_format_address in ./
uc_addresses.module - Format an address by using tokens.
File
- ./
uc_addresses.module, line 1554 - Adds user profile address support to Ubercart.
Code
function uc_addresses_get_address_format($country_id) {
static $formats = array();
if (isset($formats[$country_id])) {
return $formats[$country_id];
}
$format = variable_get('uc_addresses_address_format_' . $country_id, NULL);
if ($format) {
$formats[$country_id] = $format;
return $format;
}
$format = variable_get('uc_address_format_' . $country_id, NULL);
if ($format) {
// Convert format to tokens.
$match = array(
'/\\!([a-z\\_0-9]+)/',
);
$replace = array(
'[uc_addresses_${1}]',
);
$format = preg_replace($match, $replace, $format);
$formats[$country_id] = $format;
return $format;
}
// If nothing is returned by now, return a default address format.
return "[uc_addresses_company]\r\n[uc_addresses_first_name] [uc_addresses_last_name]\r\n[uc_addresses_street1]\r\n[uc_addresses_street2]\r\n[uc_addresses_city], [uc_addresses_zone_code] [uc_addresses_postal_code]\r\n[uc_addresses_country_name_if]";
}