Leave postcode before city swapping to JS

Fixes #6842
This commit is contained in:
Mike Jolley 2014-12-09 09:07:28 +00:00
parent 2f66bbd8c0
commit e6b94e486b
4 changed files with 7 additions and 24 deletions

File diff suppressed because one or more lines are too long

View File

@ -73,6 +73,10 @@ jQuery( function( $ ) {
$( 'body' ).trigger( 'country_to_state_changing', [country, $( this ).closest( 'div' )] );
}).change();
});
$(function() {
$( 'select.country_to_state, input.country_to_state' ).change();
});
});

View File

@ -1 +1 @@
jQuery(function(a){if("undefined"==typeof wc_country_select_params)return!1;var b=wc_country_select_params.countries.replace(/&quot;/g,'"'),c=a.parseJSON(b);a("select.country_to_state, input.country_to_state").change(function(){var b=a(this).val(),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),e=d.parent(),f=d.attr("name"),g=d.attr("id"),h=d.val(),i=d.attr("placeholder");if(c[b])if(0===c[b].length)d.parent().hide().find(".chosen-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+f+'" id="'+g+'" value="" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")]);else{var j="",k=c[b];for(var l in k)k.hasOwnProperty(l)&&(j=j+'<option value="'+l+'">'+k[l]+"</option>");d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+f+'" id="'+g+'" class="state_select" placeholder="'+i+'"></select>'),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+j),d.val(h),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])}else d.is("select")?(e.show().find(".chosen-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+f+'" id="'+g+'" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])):d.is(".hidden")&&(e.show().find(".chosen-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+f+'" id="'+g+'" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")]));a("body").trigger("country_to_state_changing",[b,a(this).closest("div")])}).change()});
jQuery(function(a){if("undefined"==typeof wc_country_select_params)return!1;var b=wc_country_select_params.countries.replace(/&quot;/g,'"'),c=a.parseJSON(b);a("select.country_to_state, input.country_to_state").change(function(){var b=a(this).val(),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),e=d.parent(),f=d.attr("name"),g=d.attr("id"),h=d.val(),i=d.attr("placeholder");if(c[b])if(0===c[b].length)d.parent().hide().find(".chosen-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+f+'" id="'+g+'" value="" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")]);else{var j="",k=c[b];for(var l in k)k.hasOwnProperty(l)&&(j=j+'<option value="'+l+'">'+k[l]+"</option>");d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+f+'" id="'+g+'" class="state_select" placeholder="'+i+'"></select>'),d=a(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+j),d.val(h),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])}else d.is("select")?(e.show().find(".chosen-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+f+'" id="'+g+'" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")])):d.is(".hidden")&&(e.show().find(".chosen-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+f+'" id="'+g+'" placeholder="'+i+'" />'),a("body").trigger("country_to_state_changed",[b,a(this).closest("div")]));a("body").trigger("country_to_state_changing",[b,a(this).closest("div")])}),a(function(){a("select.country_to_state, input.country_to_state").change()})});

View File

@ -920,28 +920,7 @@ class WC_Countries {
$locale = $this->get_country_locale();
if ( isset( $locale[ $country ] ) ) {
$fields = wc_array_overlay( $fields, $locale[ $country ] );
// If default country has postcode_before_city switch the fields round.
// This is only done at this point, not if country changes on checkout.
if ( isset( $locale[ $country ]['postcode_before_city'] ) ) {
if ( isset( $fields['postcode'] ) ) {
$fields['postcode']['class'] = array( 'form-row-wide', 'address-field' );
$switch_fields = array();
foreach ( $fields as $key => $value ) {
if ( $key == 'city' ) {
// Place postcode before city
$switch_fields['postcode'] = '';
}
$switch_fields[$key] = $value;
}
$fields = $switch_fields;
}
}
}
// Prepend field keys