Extract the autocomplete for states and countries data.
Localize it!
This commit is contained in:
parent
65eb16fe8a
commit
4221c7be24
|
@ -101,28 +101,13 @@
|
|||
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({
|
||||
source: availableCountries,
|
||||
source: data.countries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
source: data.states,
|
||||
minLength: 3
|
||||
});
|
||||
})(jQuery, htmlSettingsTaxLocalizeScript, wp);
|
||||
|
|
|
@ -19,12 +19,32 @@ foreach ( $locations as $location ) {
|
|||
$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.
|
||||
wp_localize_script( 'wc-settings-tax', 'htmlSettingsTaxLocalizeScript', array(
|
||||
'current_class' => $current_class,
|
||||
'rates' => $rates,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'countries' => $countries,
|
||||
'states' => $states,
|
||||
'strings' => array(
|
||||
'csv_data_cols' => array(
|
||||
__( 'Country Code', 'woocommerce' ),
|
||||
|
|
Loading…
Reference in New Issue