1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
jQuery(function(d){var p={states:null,init:function(){"undefined"!=typeof wc_users_params.countries&&(this.states=d.parseJSON(wc_users_params.countries.replace(/"/g,'"'))),d(".js_field-country").selectWoo().change(this.change_country),d(".js_field-country").trigger("change",[!0]),d(document.body).on("change","select.js_field-state",this.change_state),d(document.body).on("click","button.js_copy-billing",this.copy_billing)},change_country:function(e,t){if(void 0===t&&(t=!1),null!==p.states){var a=d(this),n=a.val(),i=a.parents(".form-table").find(":input.js_field-state"),c=i.parent(),s=i.attr("name"),o=i.attr("id"),l=a.data("woocommerce.stickState-"+n)?a.data("woocommerce.stickState-"+n):i.val();if(t&&a.data("woocommerce.stickState-"+n,l),c.show().find(".select2-container").remove(),d.isEmptyObject(p.states[n]))i.replaceWith('<input type="text" class="js_field-state" name="'+s+'" id="'+o+'" value="'+l+'" />');else{var r=d('<select name="'+s+'" id="'+o+'" class="js_field-state" style="width: 25em;"></select>'),u=p.states[n];r.append(d('<option value="">'+wc_users_params.i18n_select_state_text+"</option>")),d.each(u,function(e){r.append(d('<option value="'+e+'">'+u[e]+"</option>"))}),r.val(l),i.replaceWith(r),r.show().selectWoo().hide().change()}d(document.body).trigger("contry-change.woocommerce",[n,d(this).closest("div")]),d(document.body).trigger("country-change.woocommerce",[n,d(this).closest("div")])}},change_state:function(){var e=d(this),t=e.val(),a=e.parents(".form-table").find(":input.js_field-country"),n=a.val();a.data("woocommerce.stickState-"+n,t)},copy_billing:function(e){e.preventDefault(),d("#fieldset-billing").find("input, select").each(function(e,t){var a=t.name.replace(/^billing_/,"shipping_"),n=d('[name="'+a+'"]');n.length&&n.val(t.value).trigger("change")})}};p.init()}); |