Merge branch 'enhancement/21758'

This commit is contained in:
Mike Jolley 2019-01-31 13:44:35 +00:00
commit 1dea9d6f48
4 changed files with 1360 additions and 60 deletions

1348
i18n/states.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -78,7 +78,6 @@ class WC_Settings_Shipping extends WC_Settings_Page {
$settings = apply_filters(
'woocommerce_shipping_settings',
array(
array(
'title' => __( 'Shipping options', 'woocommerce' ),
'type' => 'title',
@ -242,8 +241,8 @@ class WC_Settings_Shipping extends WC_Settings_Page {
wp_die( esc_html__( 'Zone does not exist!', 'woocommerce' ) );
}
$allowed_countries = WC()->countries->get_shipping_countries();
$shipping_continents = WC()->countries->get_shipping_continents();
$allowed_countries = WC()->countries->get_shipping_countries();
$shipping_continents = WC()->countries->get_shipping_continents();
// Prepare locations.
$locations = array();

View File

@ -42,18 +42,18 @@ if ( ! defined( 'ABSPATH' ) ) {
<select multiple="multiple" data-attribute="zone_locations" id="zone_locations" name="zone_locations" data-placeholder="<?php esc_html_e( 'Select regions within this zone', 'woocommerce' ); ?>" class="wc-shipping-zone-region-select chosen_select">
<?php
foreach ( $shipping_continents as $continent_code => $continent ) {
echo '<option value="continent:' . esc_attr( $continent_code ) . '"' . wc_selected( "continent:$continent_code", $locations ) . ' alt="">' . esc_html( $continent['name'] ) . '</option>';
echo '<option value="continent:' . esc_attr( $continent_code ) . '"' . wc_selected( "continent:$continent_code", $locations ) . '>' . esc_html( $continent['name'] ) . '</option>';
$countries = array_intersect( array_keys( $allowed_countries ), $continent['countries'] );
foreach ( $countries as $country_code ) {
echo '<option value="country:' . esc_attr( $country_code ) . '"' . wc_selected( "country:$country_code", $locations ) . ' alt="' . esc_attr( $continent['name'] ) . '">' . esc_html( '&nbsp;&nbsp; ' . $allowed_countries[ $country_code ] ) . '</option>';
echo '<option value="country:' . esc_attr( $country_code ) . '"' . wc_selected( "country:$country_code", $locations ) . '>' . esc_html( '&nbsp;&nbsp; ' . $allowed_countries[ $country_code ] ) . '</option>';
$states = WC()->countries->get_states( $country_code );
if ( $states ) {
foreach ( $states as $state_code => $state_name ) {
echo '<option value="state:' . esc_attr( $country_code . ':' . $state_code ) . '"' . wc_selected( "state:$country_code:$state_code", $locations ) . ' alt="' . esc_attr( $continent['name'] . ' ' . $allowed_countries[ $country_code ] ) . '">' . esc_html( '&nbsp;&nbsp;&nbsp;&nbsp; ' . $state_name ) . '</option>';
echo '<option value="state:' . esc_attr( $country_code . ':' . $state_code ) . '"' . wc_selected( "state:$country_code:$state_code", $locations ) . '>' . esc_html( '&nbsp;&nbsp;&nbsp;&nbsp; ' . $state_name . ', ' . $allowed_countries[ $country_code ] ) . '</option>';
}
}
}

View File

@ -113,60 +113,13 @@ class WC_Countries {
/**
* 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 set to array() are blank i.e. the country has no use for the state field.
$states = array(
'AF' => array(),
'AT' => array(),
'AX' => array(),
'BE' => array(),
'BH' => array(),
'BI' => array(),
'CZ' => array(),
'DE' => array(),
'DK' => array(),
'EE' => array(),
'FI' => array(),
'FR' => array(),
'GP' => array(),
'GF' => array(),
'IS' => array(),
'IL' => array(),
'IM' => array(),
'KR' => array(),
'KW' => array(),
'LB' => array(),
'LU' => array(),
'MQ' => array(),
'MT' => array(),
'NL' => array(),
'NO' => array(),
'PL' => array(),
'PT' => array(),
'RE' => array(),
'SG' => array(),
'SK' => array(),
'SI' => array(),
'LK' => array(),
'SE' => array(),
'VN' => array(),
'YT' => array(),
);
// Load only the state files the shop owner wants/needs.
$allowed = array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() );
if ( ! empty( $allowed ) ) {
foreach ( $allowed as $code => $country ) {
if ( ! isset( $states[ $code ] ) && file_exists( WC()->plugin_path() . '/i18n/states/' . $code . '.php' ) ) {
include WC()->plugin_path() . '/i18n/states/' . $code . '.php';
}
}
}
$states = include WC()->plugin_path() . '/i18n/states.php';
$this->states = apply_filters( 'woocommerce_states', $states );
}
@ -177,8 +130,8 @@ class WC_Countries {
* @return false|array of states
*/
public function get_states( $cc = null ) {
if ( empty( $this->states ) ) {
$this->load_country_states();
if ( ! isset( $this->states ) ) {
$this->states = apply_filters( 'woocommerce_states', include WC()->plugin_path() . '/i18n/states.php' );
}
if ( ! is_null( $cc ) ) {
@ -455,7 +408,7 @@ class WC_Countries {
*
* @param string $selected_country Selected country.
* @param string $selected_state Selected state.
* @param bool $escape If should escape HTML.
* @param bool $escape If we should escape HTML.
*/
public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
if ( $this->countries ) {
@ -783,7 +736,7 @@ class WC_Countries {
'required' => false,
'hidden' => true,
),
'state' => array(
'state' => array(
'label' => __( 'Province', 'woocommerce' ),
),
),