Default currency responds to country selection in setup wizard (#17318)

* Default currency responds to country selection in wizard

* Refactor to use wp_list_pluck

* Use <script> tag to define global instead of using hidden <input>

* Revert ignoring currency option value on page load
This commit is contained in:
Paul Dechov 2017-10-26 08:39:54 -04:00 committed by Mike Jolley
parent 8590cd297c
commit 9c2df6486c
2 changed files with 12 additions and 0 deletions

View File

@ -1,4 +1,5 @@
/*global wc_setup_params */
/*global wc_setup_currencies */
jQuery( function( $ ) {
function blockWizardUI() {
$('.wc-setup-content').block({
@ -136,4 +137,9 @@ jQuery( function( $ ) {
} );
$( '.wc-wizard-services input#stripe_create_account' ).change();
$( 'select#store_country_state' ).on( 'change', function() {
var countryCode = this.value.split( ':' )[ 0 ];
$( 'select#currency_code' ).val( wc_setup_currencies[ countryCode ] ).change();
} );
} );

View File

@ -304,6 +304,9 @@ class WC_Admin_Setup_Wizard {
$state = '*';
}
$locale_info = include( WC()->plugin_path() . '/i18n/locale-info.php' );
$currency_by_country = wp_list_pluck( $locale_info, 'currency_code' );
?>
<form method="post" class="address-step">
<?php wp_nonce_field( 'wc-setup' ); ?>
@ -391,6 +394,9 @@ class WC_Admin_Setup_Wizard {
</option>
<?php endforeach; ?>
</select>
<script type="text/javascript">
var wc_setup_currencies = <?php echo json_encode( $currency_by_country ); ?>;
</script>
<label class="location-prompt" for="product_type">
<?php esc_html_e( 'What type of product do you plan to sell?', 'woocommerce' ); ?>