function uc_addresses_get_address_format in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 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/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 2006 - Adds user profile address support to Ubercart.
Code
function uc_addresses_get_address_format($country_id) {
$formats =& drupal_static(__FUNCTION__, 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]+)/',
'/country\\_/',
'/zone\\_/',
);
$replace = array(
'[uc_addresses:${1}]',
'country:country_',
'zone:zone_',
);
$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:zone_code] [uc_addresses:postal_code]\r\n[uc_addresses:country:country_name_if]";
}