2011-08-09 15:16:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-08-10 17:11:11 +00:00
|
|
|
* WooCommerce countries
|
2012-08-06 22:43:39 +00:00
|
|
|
*
|
2011-08-10 17:11:11 +00:00
|
|
|
* The WooCommerce countries class stores country/state data.
|
2011-08-09 15:16:18 +00:00
|
|
|
*
|
2012-01-27 16:38:39 +00:00
|
|
|
* @class WC_Countries
|
2012-08-14 19:42:38 +00:00
|
|
|
* @version 1.6.4
|
2012-08-14 22:43:48 +00:00
|
|
|
* @package WooCommerce/Classes
|
2013-02-20 17:14:46 +00:00
|
|
|
* @category Class
|
2012-08-14 19:42:38 +00:00
|
|
|
* @author WooThemes
|
2011-08-09 15:16:18 +00:00
|
|
|
*/
|
2012-01-27 16:38:39 +00:00
|
|
|
class WC_Countries {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of countries */
|
2012-12-14 21:37:41 +00:00
|
|
|
public $countries;
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of states */
|
2012-12-14 21:37:41 +00:00
|
|
|
public $states;
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of locales */
|
2012-12-14 21:37:41 +00:00
|
|
|
public $locale;
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of address formats for locales */
|
2012-12-14 21:37:41 +00:00
|
|
|
public $address_formats;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-11-17 10:40:32 +00:00
|
|
|
/**
|
2012-08-15 17:08:42 +00:00
|
|
|
* Constructor for the counties class - defines all countries and states.
|
2012-08-14 19:42:38 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2011-11-17 10:40:32 +00:00
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function __construct() {
|
2012-12-28 10:54:02 +00:00
|
|
|
global $woocommerce, $states;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$this->countries = apply_filters( 'woocommerce_countries', array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'AF' => __( 'Afghanistan', 'woocommerce' ),
|
|
|
|
'AX' => __( 'Åland Islands', 'woocommerce' ),
|
|
|
|
'AL' => __( 'Albania', 'woocommerce' ),
|
|
|
|
'DZ' => __( 'Algeria', 'woocommerce' ),
|
|
|
|
'AD' => __( 'Andorra', 'woocommerce' ),
|
|
|
|
'AO' => __( 'Angola', 'woocommerce' ),
|
|
|
|
'AI' => __( 'Anguilla', 'woocommerce' ),
|
|
|
|
'AQ' => __( 'Antarctica', 'woocommerce' ),
|
|
|
|
'AG' => __( 'Antigua and Barbuda', 'woocommerce' ),
|
|
|
|
'AR' => __( 'Argentina', 'woocommerce' ),
|
|
|
|
'AM' => __( 'Armenia', 'woocommerce' ),
|
|
|
|
'AW' => __( 'Aruba', 'woocommerce' ),
|
|
|
|
'AU' => __( 'Australia', 'woocommerce' ),
|
|
|
|
'AT' => __( 'Austria', 'woocommerce' ),
|
|
|
|
'AZ' => __( 'Azerbaijan', 'woocommerce' ),
|
|
|
|
'BS' => __( 'Bahamas', 'woocommerce' ),
|
|
|
|
'BH' => __( 'Bahrain', 'woocommerce' ),
|
|
|
|
'BD' => __( 'Bangladesh', 'woocommerce' ),
|
|
|
|
'BB' => __( 'Barbados', 'woocommerce' ),
|
|
|
|
'BY' => __( 'Belarus', 'woocommerce' ),
|
|
|
|
'BE' => __( 'Belgium', 'woocommerce' ),
|
2013-01-13 13:14:54 +00:00
|
|
|
'PW' => __( 'Belau', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'BZ' => __( 'Belize', 'woocommerce' ),
|
|
|
|
'BJ' => __( 'Benin', 'woocommerce' ),
|
|
|
|
'BM' => __( 'Bermuda', 'woocommerce' ),
|
|
|
|
'BT' => __( 'Bhutan', 'woocommerce' ),
|
|
|
|
'BO' => __( 'Bolivia', 'woocommerce' ),
|
2012-11-14 12:28:01 +00:00
|
|
|
'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'BA' => __( 'Bosnia and Herzegovina', 'woocommerce' ),
|
|
|
|
'BW' => __( 'Botswana', 'woocommerce' ),
|
2012-11-14 12:28:01 +00:00
|
|
|
'BV' => __( 'Bouvet Island', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'BR' => __( 'Brazil', 'woocommerce' ),
|
|
|
|
'IO' => __( 'British Indian Ocean Territory', 'woocommerce' ),
|
|
|
|
'VG' => __( 'British Virgin Islands', 'woocommerce' ),
|
|
|
|
'BN' => __( 'Brunei', 'woocommerce' ),
|
|
|
|
'BG' => __( 'Bulgaria', 'woocommerce' ),
|
|
|
|
'BF' => __( 'Burkina Faso', 'woocommerce' ),
|
|
|
|
'BI' => __( 'Burundi', 'woocommerce' ),
|
|
|
|
'KH' => __( 'Cambodia', 'woocommerce' ),
|
|
|
|
'CM' => __( 'Cameroon', 'woocommerce' ),
|
|
|
|
'CA' => __( 'Canada', 'woocommerce' ),
|
|
|
|
'CV' => __( 'Cape Verde', 'woocommerce' ),
|
|
|
|
'KY' => __( 'Cayman Islands', 'woocommerce' ),
|
|
|
|
'CF' => __( 'Central African Republic', 'woocommerce' ),
|
|
|
|
'TD' => __( 'Chad', 'woocommerce' ),
|
|
|
|
'CL' => __( 'Chile', 'woocommerce' ),
|
|
|
|
'CN' => __( 'China', 'woocommerce' ),
|
|
|
|
'CX' => __( 'Christmas Island', 'woocommerce' ),
|
|
|
|
'CC' => __( 'Cocos (Keeling) Islands', 'woocommerce' ),
|
|
|
|
'CO' => __( 'Colombia', 'woocommerce' ),
|
|
|
|
'KM' => __( 'Comoros', 'woocommerce' ),
|
|
|
|
'CG' => __( 'Congo (Brazzaville)', 'woocommerce' ),
|
|
|
|
'CD' => __( 'Congo (Kinshasa)', 'woocommerce' ),
|
|
|
|
'CK' => __( 'Cook Islands', 'woocommerce' ),
|
|
|
|
'CR' => __( 'Costa Rica', 'woocommerce' ),
|
|
|
|
'HR' => __( 'Croatia', 'woocommerce' ),
|
|
|
|
'CU' => __( 'Cuba', 'woocommerce' ),
|
2012-11-14 12:28:01 +00:00
|
|
|
'CW' => __( 'CuraÇao', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'CY' => __( 'Cyprus', 'woocommerce' ),
|
|
|
|
'CZ' => __( 'Czech Republic', 'woocommerce' ),
|
|
|
|
'DK' => __( 'Denmark', 'woocommerce' ),
|
|
|
|
'DJ' => __( 'Djibouti', 'woocommerce' ),
|
|
|
|
'DM' => __( 'Dominica', 'woocommerce' ),
|
|
|
|
'DO' => __( 'Dominican Republic', 'woocommerce' ),
|
|
|
|
'EC' => __( 'Ecuador', 'woocommerce' ),
|
|
|
|
'EG' => __( 'Egypt', 'woocommerce' ),
|
|
|
|
'SV' => __( 'El Salvador', 'woocommerce' ),
|
|
|
|
'GQ' => __( 'Equatorial Guinea', 'woocommerce' ),
|
|
|
|
'ER' => __( 'Eritrea', 'woocommerce' ),
|
|
|
|
'EE' => __( 'Estonia', 'woocommerce' ),
|
|
|
|
'ET' => __( 'Ethiopia', 'woocommerce' ),
|
|
|
|
'FK' => __( 'Falkland Islands', 'woocommerce' ),
|
|
|
|
'FO' => __( 'Faroe Islands', 'woocommerce' ),
|
|
|
|
'FJ' => __( 'Fiji', 'woocommerce' ),
|
|
|
|
'FI' => __( 'Finland', 'woocommerce' ),
|
|
|
|
'FR' => __( 'France', 'woocommerce' ),
|
|
|
|
'GF' => __( 'French Guiana', 'woocommerce' ),
|
|
|
|
'PF' => __( 'French Polynesia', 'woocommerce' ),
|
|
|
|
'TF' => __( 'French Southern Territories', 'woocommerce' ),
|
|
|
|
'GA' => __( 'Gabon', 'woocommerce' ),
|
|
|
|
'GM' => __( 'Gambia', 'woocommerce' ),
|
|
|
|
'GE' => __( 'Georgia', 'woocommerce' ),
|
|
|
|
'DE' => __( 'Germany', 'woocommerce' ),
|
|
|
|
'GH' => __( 'Ghana', 'woocommerce' ),
|
|
|
|
'GI' => __( 'Gibraltar', 'woocommerce' ),
|
|
|
|
'GR' => __( 'Greece', 'woocommerce' ),
|
|
|
|
'GL' => __( 'Greenland', 'woocommerce' ),
|
|
|
|
'GD' => __( 'Grenada', 'woocommerce' ),
|
|
|
|
'GP' => __( 'Guadeloupe', 'woocommerce' ),
|
|
|
|
'GT' => __( 'Guatemala', 'woocommerce' ),
|
|
|
|
'GG' => __( 'Guernsey', 'woocommerce' ),
|
|
|
|
'GN' => __( 'Guinea', 'woocommerce' ),
|
|
|
|
'GW' => __( 'Guinea-Bissau', 'woocommerce' ),
|
|
|
|
'GY' => __( 'Guyana', 'woocommerce' ),
|
|
|
|
'HT' => __( 'Haiti', 'woocommerce' ),
|
2012-11-14 12:28:01 +00:00
|
|
|
'HM' => __( 'Heard Island and McDonald Islands', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'HN' => __( 'Honduras', 'woocommerce' ),
|
|
|
|
'HK' => __( 'Hong Kong', 'woocommerce' ),
|
|
|
|
'HU' => __( 'Hungary', 'woocommerce' ),
|
|
|
|
'IS' => __( 'Iceland', 'woocommerce' ),
|
|
|
|
'IN' => __( 'India', 'woocommerce' ),
|
|
|
|
'ID' => __( 'Indonesia', 'woocommerce' ),
|
|
|
|
'IR' => __( 'Iran', 'woocommerce' ),
|
|
|
|
'IQ' => __( 'Iraq', 'woocommerce' ),
|
|
|
|
'IE' => __( 'Republic of Ireland', 'woocommerce' ),
|
|
|
|
'IM' => __( 'Isle of Man', 'woocommerce' ),
|
|
|
|
'IL' => __( 'Israel', 'woocommerce' ),
|
|
|
|
'IT' => __( 'Italy', 'woocommerce' ),
|
|
|
|
'CI' => __( 'Ivory Coast', 'woocommerce' ),
|
|
|
|
'JM' => __( 'Jamaica', 'woocommerce' ),
|
|
|
|
'JP' => __( 'Japan', 'woocommerce' ),
|
|
|
|
'JE' => __( 'Jersey', 'woocommerce' ),
|
|
|
|
'JO' => __( 'Jordan', 'woocommerce' ),
|
|
|
|
'KZ' => __( 'Kazakhstan', 'woocommerce' ),
|
|
|
|
'KE' => __( 'Kenya', 'woocommerce' ),
|
|
|
|
'KI' => __( 'Kiribati', 'woocommerce' ),
|
|
|
|
'KW' => __( 'Kuwait', 'woocommerce' ),
|
|
|
|
'KG' => __( 'Kyrgyzstan', 'woocommerce' ),
|
|
|
|
'LA' => __( 'Laos', 'woocommerce' ),
|
|
|
|
'LV' => __( 'Latvia', 'woocommerce' ),
|
|
|
|
'LB' => __( 'Lebanon', 'woocommerce' ),
|
|
|
|
'LS' => __( 'Lesotho', 'woocommerce' ),
|
|
|
|
'LR' => __( 'Liberia', 'woocommerce' ),
|
|
|
|
'LY' => __( 'Libya', 'woocommerce' ),
|
|
|
|
'LI' => __( 'Liechtenstein', 'woocommerce' ),
|
|
|
|
'LT' => __( 'Lithuania', 'woocommerce' ),
|
|
|
|
'LU' => __( 'Luxembourg', 'woocommerce' ),
|
|
|
|
'MO' => __( 'Macao S.A.R., China', 'woocommerce' ),
|
|
|
|
'MK' => __( 'Macedonia', 'woocommerce' ),
|
|
|
|
'MG' => __( 'Madagascar', 'woocommerce' ),
|
|
|
|
'MW' => __( 'Malawi', 'woocommerce' ),
|
|
|
|
'MY' => __( 'Malaysia', 'woocommerce' ),
|
|
|
|
'MV' => __( 'Maldives', 'woocommerce' ),
|
|
|
|
'ML' => __( 'Mali', 'woocommerce' ),
|
|
|
|
'MT' => __( 'Malta', 'woocommerce' ),
|
|
|
|
'MH' => __( 'Marshall Islands', 'woocommerce' ),
|
|
|
|
'MQ' => __( 'Martinique', 'woocommerce' ),
|
|
|
|
'MR' => __( 'Mauritania', 'woocommerce' ),
|
|
|
|
'MU' => __( 'Mauritius', 'woocommerce' ),
|
|
|
|
'YT' => __( 'Mayotte', 'woocommerce' ),
|
|
|
|
'MX' => __( 'Mexico', 'woocommerce' ),
|
|
|
|
'FM' => __( 'Micronesia', 'woocommerce' ),
|
|
|
|
'MD' => __( 'Moldova', 'woocommerce' ),
|
|
|
|
'MC' => __( 'Monaco', 'woocommerce' ),
|
|
|
|
'MN' => __( 'Mongolia', 'woocommerce' ),
|
|
|
|
'ME' => __( 'Montenegro', 'woocommerce' ),
|
|
|
|
'MS' => __( 'Montserrat', 'woocommerce' ),
|
|
|
|
'MA' => __( 'Morocco', 'woocommerce' ),
|
|
|
|
'MZ' => __( 'Mozambique', 'woocommerce' ),
|
|
|
|
'MM' => __( 'Myanmar', 'woocommerce' ),
|
|
|
|
'NA' => __( 'Namibia', 'woocommerce' ),
|
|
|
|
'NR' => __( 'Nauru', 'woocommerce' ),
|
|
|
|
'NP' => __( 'Nepal', 'woocommerce' ),
|
|
|
|
'NL' => __( 'Netherlands', 'woocommerce' ),
|
|
|
|
'AN' => __( 'Netherlands Antilles', 'woocommerce' ),
|
|
|
|
'NC' => __( 'New Caledonia', 'woocommerce' ),
|
|
|
|
'NZ' => __( 'New Zealand', 'woocommerce' ),
|
|
|
|
'NI' => __( 'Nicaragua', 'woocommerce' ),
|
|
|
|
'NE' => __( 'Niger', 'woocommerce' ),
|
|
|
|
'NG' => __( 'Nigeria', 'woocommerce' ),
|
|
|
|
'NU' => __( 'Niue', 'woocommerce' ),
|
|
|
|
'NF' => __( 'Norfolk Island', 'woocommerce' ),
|
|
|
|
'KP' => __( 'North Korea', 'woocommerce' ),
|
|
|
|
'NO' => __( 'Norway', 'woocommerce' ),
|
|
|
|
'OM' => __( 'Oman', 'woocommerce' ),
|
|
|
|
'PK' => __( 'Pakistan', 'woocommerce' ),
|
|
|
|
'PS' => __( 'Palestinian Territory', 'woocommerce' ),
|
|
|
|
'PA' => __( 'Panama', 'woocommerce' ),
|
|
|
|
'PG' => __( 'Papua New Guinea', 'woocommerce' ),
|
|
|
|
'PY' => __( 'Paraguay', 'woocommerce' ),
|
|
|
|
'PE' => __( 'Peru', 'woocommerce' ),
|
|
|
|
'PH' => __( 'Philippines', 'woocommerce' ),
|
|
|
|
'PN' => __( 'Pitcairn', 'woocommerce' ),
|
|
|
|
'PL' => __( 'Poland', 'woocommerce' ),
|
|
|
|
'PT' => __( 'Portugal', 'woocommerce' ),
|
|
|
|
'QA' => __( 'Qatar', 'woocommerce' ),
|
|
|
|
'RE' => __( 'Reunion', 'woocommerce' ),
|
|
|
|
'RO' => __( 'Romania', 'woocommerce' ),
|
|
|
|
'RU' => __( 'Russia', 'woocommerce' ),
|
|
|
|
'RW' => __( 'Rwanda', 'woocommerce' ),
|
|
|
|
'BL' => __( 'Saint Barthélemy', 'woocommerce' ),
|
|
|
|
'SH' => __( 'Saint Helena', 'woocommerce' ),
|
|
|
|
'KN' => __( 'Saint Kitts and Nevis', 'woocommerce' ),
|
|
|
|
'LC' => __( 'Saint Lucia', 'woocommerce' ),
|
|
|
|
'MF' => __( 'Saint Martin (French part)', 'woocommerce' ),
|
2012-11-14 12:28:01 +00:00
|
|
|
'SX' => __( 'Saint Martin (Dutch part)', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'PM' => __( 'Saint Pierre and Miquelon', 'woocommerce' ),
|
|
|
|
'VC' => __( 'Saint Vincent and the Grenadines', 'woocommerce' ),
|
|
|
|
'SM' => __( 'San Marino', 'woocommerce' ),
|
|
|
|
'ST' => __( 'São Tomé and Príncipe', 'woocommerce' ),
|
|
|
|
'SA' => __( 'Saudi Arabia', 'woocommerce' ),
|
|
|
|
'SN' => __( 'Senegal', 'woocommerce' ),
|
|
|
|
'RS' => __( 'Serbia', 'woocommerce' ),
|
|
|
|
'SC' => __( 'Seychelles', 'woocommerce' ),
|
|
|
|
'SL' => __( 'Sierra Leone', 'woocommerce' ),
|
|
|
|
'SG' => __( 'Singapore', 'woocommerce' ),
|
|
|
|
'SK' => __( 'Slovakia', 'woocommerce' ),
|
|
|
|
'SI' => __( 'Slovenia', 'woocommerce' ),
|
|
|
|
'SB' => __( 'Solomon Islands', 'woocommerce' ),
|
|
|
|
'SO' => __( 'Somalia', 'woocommerce' ),
|
|
|
|
'ZA' => __( 'South Africa', 'woocommerce' ),
|
|
|
|
'GS' => __( 'South Georgia/Sandwich Islands', 'woocommerce' ),
|
|
|
|
'KR' => __( 'South Korea', 'woocommerce' ),
|
2012-11-14 12:28:01 +00:00
|
|
|
'SS' => __( 'South Sudan', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'ES' => __( 'Spain', 'woocommerce' ),
|
|
|
|
'LK' => __( 'Sri Lanka', 'woocommerce' ),
|
|
|
|
'SD' => __( 'Sudan', 'woocommerce' ),
|
|
|
|
'SR' => __( 'Suriname', 'woocommerce' ),
|
|
|
|
'SJ' => __( 'Svalbard and Jan Mayen', 'woocommerce' ),
|
|
|
|
'SZ' => __( 'Swaziland', 'woocommerce' ),
|
|
|
|
'SE' => __( 'Sweden', 'woocommerce' ),
|
|
|
|
'CH' => __( 'Switzerland', 'woocommerce' ),
|
|
|
|
'SY' => __( 'Syria', 'woocommerce' ),
|
|
|
|
'TW' => __( 'Taiwan', 'woocommerce' ),
|
|
|
|
'TJ' => __( 'Tajikistan', 'woocommerce' ),
|
|
|
|
'TZ' => __( 'Tanzania', 'woocommerce' ),
|
|
|
|
'TH' => __( 'Thailand', 'woocommerce' ),
|
|
|
|
'TL' => __( 'Timor-Leste', 'woocommerce' ),
|
|
|
|
'TG' => __( 'Togo', 'woocommerce' ),
|
|
|
|
'TK' => __( 'Tokelau', 'woocommerce' ),
|
|
|
|
'TO' => __( 'Tonga', 'woocommerce' ),
|
|
|
|
'TT' => __( 'Trinidad and Tobago', 'woocommerce' ),
|
|
|
|
'TN' => __( 'Tunisia', 'woocommerce' ),
|
|
|
|
'TR' => __( 'Turkey', 'woocommerce' ),
|
|
|
|
'TM' => __( 'Turkmenistan', 'woocommerce' ),
|
|
|
|
'TC' => __( 'Turks and Caicos Islands', 'woocommerce' ),
|
|
|
|
'TV' => __( 'Tuvalu', 'woocommerce' ),
|
|
|
|
'UG' => __( 'Uganda', 'woocommerce' ),
|
|
|
|
'UA' => __( 'Ukraine', 'woocommerce' ),
|
|
|
|
'AE' => __( 'United Arab Emirates', 'woocommerce' ),
|
2013-08-13 11:38:26 +00:00
|
|
|
'GB' => __( 'United Kingdom (UK)', 'woocommerce' ),
|
|
|
|
'US' => __( 'United States (US)', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'UY' => __( 'Uruguay', 'woocommerce' ),
|
|
|
|
'UZ' => __( 'Uzbekistan', 'woocommerce' ),
|
|
|
|
'VU' => __( 'Vanuatu', 'woocommerce' ),
|
|
|
|
'VA' => __( 'Vatican', 'woocommerce' ),
|
|
|
|
'VE' => __( 'Venezuela', 'woocommerce' ),
|
|
|
|
'VN' => __( 'Vietnam', 'woocommerce' ),
|
|
|
|
'WF' => __( 'Wallis and Futuna', 'woocommerce' ),
|
|
|
|
'EH' => __( 'Western Sahara', 'woocommerce' ),
|
2013-03-07 11:01:06 +00:00
|
|
|
'WS' => __( 'Western Samoa', 'woocommerce' ),
|
2012-10-16 09:45:33 +00:00
|
|
|
'YE' => __( 'Yemen', 'woocommerce' ),
|
|
|
|
'ZM' => __( 'Zambia', 'woocommerce' ),
|
|
|
|
'ZW' => __( 'Zimbabwe', 'woocommerce' )
|
2012-03-26 17:55:30 +00:00
|
|
|
));
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-12-28 10:54:02 +00:00
|
|
|
// States set to array() are blank i.e. the country has no use for the state field.
|
|
|
|
$states = array(
|
2012-07-26 16:29:49 +00:00
|
|
|
'AF' => array(),
|
2011-12-15 19:22:15 +00:00
|
|
|
'AT' => array(),
|
2012-02-28 10:12:13 +00:00
|
|
|
'BE' => array(),
|
2012-07-26 16:29:49 +00:00
|
|
|
'BI' => array(),
|
2011-12-15 19:22:15 +00:00
|
|
|
'CZ' => array(),
|
2011-12-15 01:14:47 +00:00
|
|
|
'DE' => array(),
|
2011-12-15 19:22:15 +00:00
|
|
|
'DK' => array(),
|
2013-09-10 12:41:40 +00:00
|
|
|
'EE' => array(),
|
2011-12-15 23:24:02 +00:00
|
|
|
'FI' => array(),
|
|
|
|
'FR' => array(),
|
2011-12-16 21:19:56 +00:00
|
|
|
'IS' => array(),
|
|
|
|
'IL' => array(),
|
2013-01-20 12:50:39 +00:00
|
|
|
'KR' => array(),
|
2012-09-02 11:03:19 +00:00
|
|
|
'NL' => array(),
|
2011-12-16 21:19:56 +00:00
|
|
|
'NO' => array(),
|
|
|
|
'PL' => array(),
|
2013-02-01 10:56:40 +00:00
|
|
|
'PT' => array(),
|
2011-12-16 21:19:56 +00:00
|
|
|
'SG' => array(),
|
|
|
|
'SK' => array(),
|
|
|
|
'SI' => array(),
|
|
|
|
'LK' => array(),
|
|
|
|
'SE' => array(),
|
2013-03-05 08:47:38 +00:00
|
|
|
'VN' => array(),
|
2012-12-28 10:54:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Load only the state files the shop owner wants/needs
|
2013-08-02 15:54:28 +00:00
|
|
|
$allowed = array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() );
|
2012-12-28 10:54:02 +00:00
|
|
|
|
|
|
|
if ( $allowed )
|
|
|
|
foreach ( $allowed as $CC => $country )
|
2013-11-25 14:01:32 +00:00
|
|
|
if ( ! isset( $states[ $CC ] ) && file_exists( WC()->plugin_path() . '/i18n/states/' . $CC . '.php' ) )
|
|
|
|
include( WC()->plugin_path() . '/i18n/states/' . $CC . '.php' );
|
2012-12-28 10:54:02 +00:00
|
|
|
|
2013-09-24 15:56:55 +00:00
|
|
|
$this->states = apply_filters( 'woocommerce_states', $states );
|
2011-11-17 10:40:32 +00:00
|
|
|
}
|
2012-01-16 06:37:50 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Get the base country for the store.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_base_country() {
|
2012-10-18 10:33:47 +00:00
|
|
|
$default = esc_attr( get_option('woocommerce_default_country') );
|
2013-09-27 19:31:59 +00:00
|
|
|
$country = ( ( $pos = strrpos( $default, ':' ) ) === false ) ? $default : substr( $default, 0, $pos );
|
2012-01-16 06:37:50 +00:00
|
|
|
|
2013-09-24 15:56:55 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_base_country', $country );
|
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-24 15:56:55 +00:00
|
|
|
* Get the base state for the store.
|
2012-08-14 19:42:38 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_base_state() {
|
2013-11-25 13:34:21 +00:00
|
|
|
$default = wc_clean( get_option( 'woocommerce_default_country' ) );
|
2013-09-24 15:56:55 +00:00
|
|
|
$state = ( ( $pos = strrpos( $default, ':' ) ) === false ) ? '' : substr( $default, $pos + 1 );
|
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_countries_base_state', $state );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base city for the store.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_base_city() {
|
|
|
|
return apply_filters( 'woocommerce_countries_base_city', '' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base postcode for the store.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_base_postcode() {
|
|
|
|
return apply_filters( 'woocommerce_countries_base_postcode', '' );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-01-16 06:37:50 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Get the allowed countries for the store.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_allowed_countries() {
|
2013-01-03 12:34:31 +00:00
|
|
|
|
2013-01-02 17:05:54 +00:00
|
|
|
if ( apply_filters('woocommerce_sort_countries', true ) )
|
|
|
|
asort( $this->countries );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-11-27 16:22:47 +00:00
|
|
|
if ( get_option('woocommerce_allowed_countries') !== 'specific' )
|
2012-08-22 15:13:58 +00:00
|
|
|
return $this->countries;
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$countries = array();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$raw_countries = get_option( 'woocommerce_specific_allowed_countries' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
foreach ( $raw_countries as $country )
|
|
|
|
$countries[ $country ] = $this->countries[ $country ];
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_allowed_countries', $countries );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
/**
|
|
|
|
* Get the countries you ship to.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_shipping_countries() {
|
|
|
|
|
|
|
|
if ( apply_filters( 'woocommerce_sort_countries', true ) )
|
|
|
|
asort( $this->countries );
|
|
|
|
|
|
|
|
if ( get_option( 'woocommerce_ship_to_countries' ) == '' )
|
|
|
|
return $this->get_allowed_countries();
|
|
|
|
|
|
|
|
if ( get_option('woocommerce_ship_to_countries') !== 'specific' )
|
|
|
|
return $this->countries;
|
|
|
|
|
|
|
|
$countries = array();
|
|
|
|
|
|
|
|
$raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
|
|
|
|
|
|
|
|
foreach ( $raw_countries as $country )
|
|
|
|
$countries[ $country ] = $this->countries[ $country ];
|
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_countries_shipping_countries', $countries );
|
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-08-22 15:13:58 +00:00
|
|
|
/**
|
|
|
|
* get_allowed_country_states function.
|
2012-11-27 16:22:47 +00:00
|
|
|
*
|
2012-08-22 15:13:58 +00:00
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_allowed_country_states() {
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2012-11-27 16:22:47 +00:00
|
|
|
if ( get_option('woocommerce_allowed_countries') !== 'specific' )
|
2012-08-22 15:13:58 +00:00
|
|
|
return $this->states;
|
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$states = array();
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$raw_countries = get_option( 'woocommerce_specific_allowed_countries' );
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
foreach ( $raw_countries as $country )
|
2013-11-27 15:38:52 +00:00
|
|
|
if ( isset( $this->states[ $country ] ) )
|
2013-08-02 15:54:28 +00:00
|
|
|
$states[ $country ] = $this->states[ $country ];
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_allowed_country_states', $states );
|
2012-08-22 15:13:58 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
/**
|
|
|
|
* get_shipping_country_states function.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_shipping_country_states() {
|
|
|
|
|
|
|
|
if ( get_option( 'woocommerce_ship_to_countries' ) == '' )
|
|
|
|
return $this->get_allowed_country_states();
|
|
|
|
|
|
|
|
if ( get_option( 'woocommerce_ship_to_countries' ) !== 'specific' )
|
|
|
|
return $this->states;
|
|
|
|
|
|
|
|
$states = array();
|
|
|
|
|
|
|
|
$raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
|
|
|
|
|
|
|
|
foreach ( $raw_countries as $country )
|
|
|
|
if ( ! empty( $this->states[ $country ] ) )
|
|
|
|
$states[ $country ] = $this->states[ $country ];
|
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_countries_shipping_country_states', $states );
|
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array of countries in the EU.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_european_union_countries() {
|
2013-08-09 10:11:48 +00:00
|
|
|
return array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the correct string for shipping - ether 'to the' or 'to'
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function shipping_to_prefix() {
|
2011-08-09 15:16:18 +00:00
|
|
|
$return = '';
|
2013-11-25 14:01:32 +00:00
|
|
|
if (in_array(WC()->customer->get_shipping_country(), array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' ))) $return = __( 'to the', 'woocommerce' );
|
2012-10-16 09:45:33 +00:00
|
|
|
else $return = __( 'to', 'woocommerce' );
|
2013-11-25 14:01:32 +00:00
|
|
|
return apply_filters('woocommerce_countries_shipping_to_prefix', $return, WC()->customer->get_shipping_country());
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefix certain countries with 'the'
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function estimated_for_prefix() {
|
2011-08-09 15:16:18 +00:00
|
|
|
$return = '';
|
2012-10-16 09:45:33 +00:00
|
|
|
if (in_array($this->get_base_country(), array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' ))) $return = __( 'the', 'woocommerce' ) . ' ';
|
2011-12-14 23:50:32 +00:00
|
|
|
return apply_filters('woocommerce_countries_estimated_for_prefix', $return, $this->get_base_country());
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Correctly name tax in some countries VAT on the frontend
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function tax_or_vat() {
|
2012-10-16 09:45:33 +00:00
|
|
|
$return = ( in_array($this->get_base_country(), $this->get_european_union_countries()) ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the Inc Tax label.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function inc_tax_or_vat() {
|
2012-10-16 09:45:33 +00:00
|
|
|
$return = ( in_array($this->get_base_country(), $this->get_european_union_countries()) ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Include the Ex Tax label.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function ex_tax_or_vat() {
|
2012-10-16 09:45:33 +00:00
|
|
|
$return = ( in_array($this->get_base_country(), $this->get_european_union_countries()) ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the states for a country.
|
|
|
|
*
|
|
|
|
* @access public
|
2013-12-02 13:42:39 +00:00
|
|
|
* @param string $cc country code
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return array of states
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_states( $cc ) {
|
2013-12-03 14:03:25 +00:00
|
|
|
return ( isset( $this->states[ $cc ] ) ) ? $this->states[ $cc ] : array();
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the list of countries and states for use in dropdown boxes.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param string $selected_country (default: '')
|
|
|
|
* @param string $selected_state (default: '')
|
|
|
|
* @param bool $escape (default: false)
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-01-02 17:05:54 +00:00
|
|
|
if ( apply_filters('woocommerce_sort_countries', true ) )
|
|
|
|
asort( $this->countries );
|
2012-02-29 15:47:19 +00:00
|
|
|
|
2012-01-16 06:40:13 +00:00
|
|
|
if ( $this->countries ) foreach ( $this->countries as $key=>$value) :
|
2011-09-06 11:11:22 +00:00
|
|
|
if ( $states = $this->get_states($key) ) :
|
2013-11-20 19:11:59 +00:00
|
|
|
echo '<optgroup label="' . esc_attr( $value ) . '">';
|
2011-08-09 15:16:18 +00:00
|
|
|
foreach ($states as $state_key=>$state_value) :
|
2013-11-20 19:11:59 +00:00
|
|
|
echo '<option value="' . esc_attr( $key ) . ':'.$state_key.'"';
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
if ($selected_country==$key && $selected_state==$state_key) echo ' selected="selected"';
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
echo '>'.$value.' — '. ($escape ? esc_js($state_value) : $state_value) .'</option>';
|
|
|
|
endforeach;
|
|
|
|
echo '</optgroup>';
|
|
|
|
else :
|
|
|
|
echo '<option';
|
|
|
|
if ($selected_country==$key && $selected_state=='*') echo ' selected="selected"';
|
2013-11-20 19:11:59 +00:00
|
|
|
echo ' value="' . esc_attr( $key ) . '">'. ($escape ? esc_js( $value ) : $value) .'</option>';
|
2011-08-09 15:16:18 +00:00
|
|
|
endif;
|
|
|
|
endforeach;
|
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get country address formats
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_address_formats() {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-15 23:24:02 +00:00
|
|
|
if (!$this->address_formats) :
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-16 21:19:56 +00:00
|
|
|
// Common formats
|
|
|
|
$postcode_before_city = "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}";
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-16 21:19:56 +00:00
|
|
|
// Define address formats
|
2011-12-15 23:24:02 +00:00
|
|
|
$this->address_formats = apply_filters('woocommerce_localisation_address_formats', array(
|
|
|
|
'default' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}",
|
|
|
|
'AU' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {state} {postcode}\n{country}",
|
2011-12-16 21:19:56 +00:00
|
|
|
'AT' => $postcode_before_city,
|
2012-02-13 10:36:16 +00:00
|
|
|
'BE' => $postcode_before_city,
|
2012-07-10 12:36:13 +00:00
|
|
|
'CH' => $postcode_before_city,
|
2011-12-15 23:24:02 +00:00
|
|
|
'CN' => "{country} {postcode}\n{state}, {city}, {address_2}, {address_1}\n{company}\n{name}",
|
2011-12-16 21:19:56 +00:00
|
|
|
'CZ' => $postcode_before_city,
|
|
|
|
'DE' => $postcode_before_city,
|
2013-09-10 12:41:40 +00:00
|
|
|
'EE' => $postcode_before_city,
|
2011-12-16 21:19:56 +00:00
|
|
|
'FI' => $postcode_before_city,
|
|
|
|
'DK' => $postcode_before_city,
|
2011-12-15 23:24:02 +00:00
|
|
|
'FR' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city_upper}\n{country}",
|
2011-12-16 21:19:56 +00:00
|
|
|
'HK' => "{company}\n{first_name} {last_name_upper}\n{address_1}\n{address_2}\n{city_upper}\n{state_upper}\n{country}",
|
|
|
|
'HU' => "{name}\n{company}\n{city}\n{address_1}\n{address_2}\n{postcode}\n{country}",
|
|
|
|
'IS' => $postcode_before_city,
|
2013-06-04 12:30:39 +00:00
|
|
|
'IT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city} {state_upper}\n{country}",
|
2013-12-30 21:35:21 +00:00
|
|
|
'JP' => "{postcode}\n{state}{city}{address_2}\n{address_1}\n{company}\n{last_name} {first_name}\n {country}",
|
2012-07-10 12:36:13 +00:00
|
|
|
'LI' => $postcode_before_city,
|
2011-12-16 21:19:56 +00:00
|
|
|
'NL' => $postcode_before_city,
|
|
|
|
'NZ' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
|
|
|
|
'NO' => $postcode_before_city,
|
|
|
|
'PL' => $postcode_before_city,
|
|
|
|
'SK' => $postcode_before_city,
|
|
|
|
'SI' => $postcode_before_city,
|
|
|
|
'ES' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}",
|
|
|
|
'SE' => $postcode_before_city,
|
|
|
|
'TR' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city} {state}\n{country}",
|
|
|
|
'US' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state} {postcode}\n{country}",
|
2012-03-14 20:35:42 +00:00
|
|
|
'VN' => "{name}\n{company}\n{address_1}\n{city}\n{country}",
|
2011-12-15 23:24:02 +00:00
|
|
|
));
|
|
|
|
endif;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
return $this->address_formats;
|
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get country address format
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $args (default: array())
|
|
|
|
* @return string address
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_formatted_address( $args = array() ) {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-10-16 15:22:07 +00:00
|
|
|
$args = array_map( 'trim', $args );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
extract( $args );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// Get all formats
|
2011-12-18 13:41:42 +00:00
|
|
|
$formats = $this->get_address_formats();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// Get format for the address' country
|
2012-10-16 15:22:07 +00:00
|
|
|
$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// Handle full country name
|
2012-10-16 15:22:07 +00:00
|
|
|
$full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-28 12:38:49 +00:00
|
|
|
// Country is not needed if the same as base
|
2013-05-13 13:35:49 +00:00
|
|
|
if ( $country == $this->get_base_country() && ! apply_filters( 'woocommerce_formatted_address_force_country_display', false ) )
|
2012-10-16 15:22:07 +00:00
|
|
|
$format = str_replace( '{country}', '', $format );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 13:41:42 +00:00
|
|
|
// Handle full state name
|
2012-10-16 15:22:07 +00:00
|
|
|
$full_state = ( $country && $state && isset( $this->states[ $country ][ $state ] ) ) ? $this->states[ $country ][ $state ] : $state;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// Substitute address parts into the string
|
2012-10-16 15:22:07 +00:00
|
|
|
$replace = apply_filters( 'woocommerce_formatted_address_replacements', array(
|
2012-01-15 06:22:43 +00:00
|
|
|
'{first_name}' => $first_name,
|
|
|
|
'{last_name}' => $last_name,
|
|
|
|
'{name}' => $first_name . ' ' . $last_name,
|
|
|
|
'{company}' => $company,
|
|
|
|
'{address_1}' => $address_1,
|
|
|
|
'{address_2}' => $address_2,
|
|
|
|
'{city}' => $city,
|
|
|
|
'{state}' => $full_state,
|
|
|
|
'{postcode}' => $postcode,
|
|
|
|
'{country}' => $full_country,
|
2012-10-16 15:22:07 +00:00
|
|
|
'{first_name_upper}' => strtoupper( $first_name ),
|
|
|
|
'{last_name_upper}' => strtoupper( $last_name ),
|
|
|
|
'{name_upper}' => strtoupper( $first_name . ' ' . $last_name ),
|
|
|
|
'{company_upper}' => strtoupper( $company ),
|
|
|
|
'{address_1_upper}' => strtoupper( $address_1 ),
|
|
|
|
'{address_2_upper}' => strtoupper( $address_2 ),
|
|
|
|
'{city_upper}' => strtoupper( $city ),
|
|
|
|
'{state_upper}' => strtoupper( $full_state ),
|
|
|
|
'{postcode_upper}' => strtoupper( $postcode ),
|
|
|
|
'{country_upper}' => strtoupper( $full_country ),
|
2013-04-07 08:30:02 +00:00
|
|
|
), $args ) ;
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-10-16 15:22:07 +00:00
|
|
|
$replace = array_map( 'esc_html', $replace );
|
|
|
|
|
|
|
|
$formatted_address = str_replace( array_keys( $replace ), $replace, $format );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-01-15 06:31:47 +00:00
|
|
|
// Clean up white space
|
2012-10-16 15:22:07 +00:00
|
|
|
$formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) );
|
|
|
|
$formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// Add html breaks
|
2012-10-16 15:22:07 +00:00
|
|
|
$formatted_address = nl2br( $formatted_address );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// We're done!
|
|
|
|
return $formatted_address;
|
2011-12-15 23:24:02 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the fields we show by default. This can be filtered later on.
|
|
|
|
*
|
|
|
|
* @access public
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return array
|
2013-03-18 12:02:36 +00:00
|
|
|
*/
|
|
|
|
public function get_default_address_fields() {
|
|
|
|
$fields = array(
|
2013-04-24 12:20:23 +00:00
|
|
|
'country' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'type' => 'country',
|
|
|
|
'label' => __( 'Country', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'first_name' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'label' => __( 'First Name', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-first' ),
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'last_name' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'label' => __( 'Last Name', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-last' ),
|
|
|
|
'clear' => true
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'company' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'label' => __( 'Company Name', 'woocommerce' ),
|
|
|
|
'class' => array( 'form-row-wide' ),
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'address_1' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'label' => __( 'Address', 'woocommerce' ),
|
|
|
|
'placeholder' => _x( 'Street address', 'placeholder', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-wide', 'address-field' )
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'address_2' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'placeholder' => _x( 'Apartment, suite, unit etc. (optional)', 'placeholder', 'woocommerce' ),
|
|
|
|
'class' => array( 'form-row-wide', 'address-field' ),
|
|
|
|
'required' => false
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'city' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'label' => __( 'Town / City', 'woocommerce' ),
|
|
|
|
'placeholder' => __( 'Town / City', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-wide', 'address-field' )
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'state' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'type' => 'state',
|
|
|
|
'label' => __( 'State / County', 'woocommerce' ),
|
|
|
|
'placeholder' => __( 'State / County', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-first', 'address-field' ),
|
|
|
|
'validate' => array( 'state' )
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
|
|
|
'postcode' => array(
|
2013-09-19 13:39:49 +00:00
|
|
|
'label' => __( 'Postcode / Zip', 'woocommerce' ),
|
|
|
|
'placeholder' => __( 'Postcode / Zip', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-last', 'address-field' ),
|
|
|
|
'clear' => true,
|
|
|
|
'validate' => array( 'postcode' )
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2013-03-18 12:02:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_default_address_fields', $fields );
|
|
|
|
}
|
|
|
|
|
2013-11-28 14:46:08 +00:00
|
|
|
/**
|
2013-12-03 12:14:12 +00:00
|
|
|
* Get JS selectors for fields which are shown/hidden depending on the locale.
|
2013-11-28 14:46:08 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
2013-12-03 12:14:12 +00:00
|
|
|
public function get_country_locale_field_selectors() {
|
2013-11-28 14:46:08 +00:00
|
|
|
$locale_fields = array (
|
|
|
|
'address_1' => '#billing_address_1_field, #shipping_address_1_field',
|
|
|
|
'address_2' => '#billing_address_2_field, #shipping_address_2_field',
|
|
|
|
'state' => '#billing_state_field, #shipping_state_field',
|
|
|
|
'postcode' => '#billing_postcode_field, #shipping_postcode_field',
|
|
|
|
'city' => '#billing_city_field, #shipping_city_field'
|
|
|
|
);
|
|
|
|
|
2013-12-03 12:14:12 +00:00
|
|
|
return apply_filters( 'woocommerce_country_locale_field_selectors', $locale_fields );
|
2013-11-28 14:46:08 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Get country locale settings
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_country_locale() {
|
2012-04-10 12:07:23 +00:00
|
|
|
if ( ! $this->locale ) {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-15 23:24:02 +00:00
|
|
|
// Locale information used by the checkout
|
2012-04-10 12:07:23 +00:00
|
|
|
$this->locale = apply_filters('woocommerce_get_country_locale', array(
|
2013-07-19 14:08:40 +00:00
|
|
|
'AE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true
|
|
|
|
),
|
|
|
|
),
|
2012-07-26 16:29:49 +00:00
|
|
|
'AF' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2011-12-15 23:24:02 +00:00
|
|
|
'AT' => array(
|
2011-12-16 15:11:41 +00:00
|
|
|
'postcode_before_city' => true,
|
2011-12-15 23:24:02 +00:00
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2012-02-28 10:12:13 +00:00
|
|
|
'BE' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
2013-01-27 11:26:26 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
2012-02-28 10:12:13 +00:00
|
|
|
),
|
|
|
|
),
|
2012-07-26 16:29:49 +00:00
|
|
|
'BI' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2013-11-26 21:41:54 +00:00
|
|
|
'BO' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true
|
|
|
|
),
|
|
|
|
),
|
2011-12-15 23:24:02 +00:00
|
|
|
'CA' => array(
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
2011-12-15 23:24:02 +00:00
|
|
|
)
|
|
|
|
),
|
2012-07-10 12:36:13 +00:00
|
|
|
'CH' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Canton', 'woocommerce' ),
|
2012-07-10 12:36:13 +00:00
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2011-12-15 23:24:02 +00:00
|
|
|
'CL' => array(
|
2011-12-16 21:19:56 +00:00
|
|
|
'city' => array(
|
2011-12-15 23:24:02 +00:00
|
|
|
'required' => false,
|
2011-12-16 21:19:56 +00:00
|
|
|
),
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Municipality', 'woocommerce' ),
|
2011-12-15 23:24:02 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'CN' => array(
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
2011-12-15 23:24:02 +00:00
|
|
|
)
|
|
|
|
),
|
2012-07-09 14:46:51 +00:00
|
|
|
'CO' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2012-02-12 15:37:57 +00:00
|
|
|
'CZ' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2011-12-15 23:24:02 +00:00
|
|
|
'DE' => array(
|
2011-12-16 15:11:41 +00:00
|
|
|
'postcode_before_city' => true,
|
2011-12-15 23:24:02 +00:00
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'DK' => array(
|
2011-12-16 15:11:41 +00:00
|
|
|
'postcode_before_city' => true,
|
2011-12-15 23:24:02 +00:00
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2013-09-10 12:41:40 +00:00
|
|
|
'EE' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2011-12-15 23:24:02 +00:00
|
|
|
'FI' => array(
|
2011-12-16 15:11:41 +00:00
|
|
|
'postcode_before_city' => true,
|
2011-12-15 23:24:02 +00:00
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'FR' => array(
|
2011-12-16 15:11:41 +00:00
|
|
|
'postcode_before_city' => true,
|
2011-12-15 23:24:02 +00:00
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'HK' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false
|
|
|
|
),
|
|
|
|
'city' => array(
|
2013-01-03 12:34:31 +00:00
|
|
|
'label' => __( 'Town / District', 'woocommerce' ),
|
2011-12-15 23:24:02 +00:00
|
|
|
),
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Region', 'woocommerce' ),
|
2011-12-15 23:24:02 +00:00
|
|
|
)
|
|
|
|
),
|
2011-12-16 21:19:56 +00:00
|
|
|
'HU' => array(
|
2013-08-01 14:58:48 +00:00
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'County', 'woocommerce' ),
|
2011-12-16 21:19:56 +00:00
|
|
|
)
|
|
|
|
),
|
2013-02-05 21:55:21 +00:00
|
|
|
'ID' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
)
|
|
|
|
),
|
2011-12-16 21:19:56 +00:00
|
|
|
'IS' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'IL' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2013-06-04 12:30:39 +00:00
|
|
|
'IT' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => true,
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
)
|
|
|
|
),
|
2013-07-15 08:22:48 +00:00
|
|
|
'JP' => array(
|
2014-01-03 21:46:00 +00:00
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' )
|
2013-07-15 08:22:48 +00:00
|
|
|
)
|
|
|
|
),
|
2013-01-20 13:10:36 +00:00
|
|
|
'KR' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2011-12-16 21:19:56 +00:00
|
|
|
'NL' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
2013-01-27 11:26:26 +00:00
|
|
|
'required' => false,
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
2011-12-16 21:19:56 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'NZ' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'NO' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'PL' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2013-03-19 21:33:01 +00:00
|
|
|
'PT' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2011-12-16 21:19:56 +00:00
|
|
|
'RO' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'SG' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'SK' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'SI' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ES' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
2011-12-16 21:19:56 +00:00
|
|
|
)
|
|
|
|
),
|
2012-07-10 12:36:13 +00:00
|
|
|
'LI' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Municipality', 'woocommerce' ),
|
2012-07-10 12:36:13 +00:00
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
2011-12-16 21:19:56 +00:00
|
|
|
'LK' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'SE' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'TR' => array(
|
|
|
|
'postcode_before_city' => true,
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
2011-12-16 21:19:56 +00:00
|
|
|
)
|
|
|
|
),
|
2011-12-16 15:11:41 +00:00
|
|
|
'US' => array(
|
|
|
|
'postcode' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Zip', 'woocommerce' ),
|
2011-12-16 15:11:41 +00:00
|
|
|
),
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'State', 'woocommerce' ),
|
2011-12-16 15:11:41 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'GB' => array(
|
|
|
|
'postcode' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Postcode', 'woocommerce' ),
|
2011-12-16 15:11:41 +00:00
|
|
|
),
|
|
|
|
'state' => array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'County', 'woocommerce' ),
|
2012-03-26 19:35:55 +00:00
|
|
|
'required' => false
|
2011-12-16 15:11:41 +00:00
|
|
|
)
|
|
|
|
),
|
2012-03-14 20:35:42 +00:00
|
|
|
'VN' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false
|
|
|
|
),
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true
|
|
|
|
),
|
|
|
|
'address_2' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true
|
|
|
|
)
|
2012-08-06 22:43:39 +00:00
|
|
|
),
|
2013-03-07 11:01:06 +00:00
|
|
|
'WS' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true
|
|
|
|
),
|
|
|
|
),
|
2013-03-05 18:53:47 +00:00
|
|
|
'ZA' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
)
|
|
|
|
),
|
2013-02-01 14:53:44 +00:00
|
|
|
'ZW' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true
|
|
|
|
),
|
|
|
|
),
|
2011-12-16 21:19:56 +00:00
|
|
|
));
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$this->locale = array_intersect_key( $this->locale, array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() ) );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
// Default Locale Can be filters to override fields in get_address_fields().
|
|
|
|
// Countries with no specific locale will use default.
|
|
|
|
$this->locale['default'] = apply_filters('woocommerce_get_country_locale_default', $this->get_default_address_fields() );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-04-10 12:07:23 +00:00
|
|
|
// Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout
|
2013-03-18 12:02:36 +00:00
|
|
|
if ( ! isset( $this->locale[ $this->get_base_country() ] ) )
|
|
|
|
$this->locale[ $this->get_base_country() ] = $this->locale['default'];
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-04-10 12:07:23 +00:00
|
|
|
$this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
|
2012-08-06 22:43:39 +00:00
|
|
|
$this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
|
2012-04-10 12:07:23 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-16 15:11:41 +00:00
|
|
|
return $this->locale;
|
2011-12-15 23:24:02 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
/**
|
|
|
|
* Apply locale and get address fields
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $country
|
|
|
|
* @param string $type (default: 'billing_')
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return array
|
2013-03-18 12:02:36 +00:00
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_address_fields( $country, $type = 'billing_' ) {
|
2013-07-14 23:25:12 +00:00
|
|
|
|
|
|
|
if (!$country)
|
|
|
|
$country = $this->get_base_country();
|
2013-07-19 14:08:40 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
$fields = $this->get_default_address_fields();
|
2011-12-16 15:11:41 +00:00
|
|
|
$locale = $this->get_country_locale();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-01-03 12:34:31 +00:00
|
|
|
if ( isset( $locale[ $country ] ) ) {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-11-25 13:34:21 +00:00
|
|
|
$fields = wc_array_overlay( $fields, $locale[ $country ] );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-01-03 12:34:31 +00:00
|
|
|
// If default country has postcode_before_city switch the fields round.
|
|
|
|
// This is only done at this point, not if country changes on checkout.
|
|
|
|
if ( isset( $locale[ $country ]['postcode_before_city'] ) ) {
|
2013-03-18 12:02:36 +00:00
|
|
|
if ( isset( $fields['postcode'] ) ) {
|
|
|
|
$fields['postcode']['class'] = array( 'form-row-wide', 'address-field' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
$switch_fields = array();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
foreach ( $fields as $key => $value ) {
|
|
|
|
if ( $key == 'city' ) {
|
|
|
|
// Place postcode before city
|
|
|
|
$switch_fields['postcode'] = '';
|
|
|
|
}
|
|
|
|
$switch_fields[$key] = $value;
|
2012-07-10 12:36:13 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
$fields = $switch_fields;
|
|
|
|
}
|
2012-07-10 12:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-16 15:11:41 +00:00
|
|
|
// Prepend field keys
|
|
|
|
$address_fields = array();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-07-10 12:36:13 +00:00
|
|
|
foreach ( $fields as $key => $value ) {
|
2011-12-16 15:11:41 +00:00
|
|
|
$address_fields[$type . $key] = $value;
|
2012-07-10 12:36:13 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-16 15:11:41 +00:00
|
|
|
// Billing/Shipping Specific
|
2012-07-10 12:36:13 +00:00
|
|
|
if ( $type == 'billing_' ) {
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2011-12-16 15:11:41 +00:00
|
|
|
$address_fields['billing_email'] = array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Email Address', 'woocommerce' ),
|
2012-08-06 22:43:39 +00:00
|
|
|
'required' => true,
|
2013-01-03 12:34:31 +00:00
|
|
|
'class' => array( 'form-row-first' ),
|
|
|
|
'validate' => array( 'email' ),
|
2012-08-06 22:43:39 +00:00
|
|
|
);
|
2011-12-16 15:11:41 +00:00
|
|
|
$address_fields['billing_phone'] = array(
|
2012-10-16 09:45:33 +00:00
|
|
|
'label' => __( 'Phone', 'woocommerce' ),
|
2012-08-06 22:43:39 +00:00
|
|
|
'required' => true,
|
2013-01-03 12:34:31 +00:00
|
|
|
'class' => array( 'form-row-last' ),
|
2013-09-19 13:39:49 +00:00
|
|
|
'clear' => true,
|
|
|
|
'validate' => array( 'phone' ),
|
2011-12-16 15:11:41 +00:00
|
|
|
);
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-07-10 12:36:13 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-09-10 12:39:23 +00:00
|
|
|
$address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );
|
|
|
|
|
2011-12-16 15:11:41 +00:00
|
|
|
// Return
|
|
|
|
return $address_fields;
|
|
|
|
}
|
2013-06-04 12:30:39 +00:00
|
|
|
}
|