Extract the autocomplete for states and countries data.

Localize it!
This commit is contained in:
George Stephanis 2015-08-07 11:57:38 -04:00
parent 65eb16fe8a
commit 4221c7be24
2 changed files with 22 additions and 17 deletions

View File

@ -101,28 +101,13 @@
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) ); jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
}); });
var availableCountries = [<?php
$countries = array();
foreach ( WC()->countries->get_allowed_countries() as $value => $label )
$countries[] = '{ label: "' . esc_attr( $label ) . '", value: "' . $value . '" }';
echo implode( ', ', $countries );
?>];
var availableStates = [<?php
$countries = array();
foreach ( WC()->countries->get_allowed_country_states() as $value => $label )
foreach ( $label as $code => $state )
$countries[] = '{ label: "' . esc_attr( $state ) . '", value: "' . $code . '" }';
echo implode( ', ', $countries );
?>];
jQuery( "td.country input" ).autocomplete({ jQuery( "td.country input" ).autocomplete({
source: availableCountries, source: data.countries,
minLength: 3 minLength: 3
}); });
jQuery( "td.state input" ).autocomplete({ jQuery( "td.state input" ).autocomplete({
source: availableStates, source: data.states,
minLength: 3 minLength: 3
}); });
})(jQuery, htmlSettingsTaxLocalizeScript, wp); })(jQuery, htmlSettingsTaxLocalizeScript, wp);

View File

@ -19,12 +19,32 @@ foreach ( $locations as $location ) {
$rates[ $location->tax_rate_id ]->{$location->location_type}[] = $location->location_code; $rates[ $location->tax_rate_id ]->{$location->location_type}[] = $location->location_code;
} }
$countries = array();
foreach ( WC()->countries->get_allowed_countries() as $value => $label ) {
$countries[] = array(
'label' => $label,
'value' => $value,
);
}
$states = array();
foreach ( WC()->countries->get_allowed_country_states() as $label ) {
foreach ( $label as $code => $state ) {
$states[] = array(
'label' => $state,
'value' => $code,
);
}
}
// Localize and enqueue our js. // Localize and enqueue our js.
wp_localize_script( 'wc-settings-tax', 'htmlSettingsTaxLocalizeScript', array( wp_localize_script( 'wc-settings-tax', 'htmlSettingsTaxLocalizeScript', array(
'current_class' => $current_class, 'current_class' => $current_class,
'rates' => $rates, 'rates' => $rates,
'page' => $page, 'page' => $page,
'limit' => $limit, 'limit' => $limit,
'countries' => $countries,
'states' => $states,
'strings' => array( 'strings' => array(
'csv_data_cols' => array( 'csv_data_cols' => array(
__( 'Country Code', 'woocommerce' ), __( 'Country Code', 'woocommerce' ),