From 13c529be93004be2a35885e018e6a1c4d888c47c Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Sun, 1 Mar 2020 18:52:23 +0000 Subject: [PATCH 1/4] Update meta-boxes-order.js - add props via jquery, not direct WC commit b626945 --- assets/js/admin/meta-boxes-order.js | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index 18bfdce16c..2d57cbe368 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -53,22 +53,34 @@ jQuery( function ( $ ) { $parent.show().find( '.select2-container' ).remove(); if ( ! $.isEmptyObject( wc_meta_boxes_order.states[ country ] ) ) { - var $states_select = $( '' ), - state = wc_meta_boxes_order.states[ country ]; - - $states_select.append( $( '' ) ); - - $.each( state, function( index ) { - $states_select.append( $( '' ) ); - } ); + var state = wc_meta_boxes_order.states[ country ], + $newstate = $( '' ) + .prop( 'id', input_id ) + .prop( 'name', input_name ) + .prop( 'placeholder', placeholder ) + .addClass( 'js_field-state select short' ) + .append( $( '' ) ); + + $.each( state, function( index ) { + var $option = $( '' ) + .prop( 'value', index ) + .text( state[ index ] ); + $newstate.append( $option ); + } ); - $states_select.val( value ); + $newstate.val( value ); - $state.replaceWith( $states_select ); + $state.replaceWith( $newstate ); - $states_select.show().selectWoo().hide().change(); + $newstate.show().selectWoo().hide().change(); } else { - $state.replaceWith( '' ); + var $newstate = $( '' ) + .prop( 'id', input_id ) + .prop( 'name', input_name ) + .prop( 'placeholder', placeholder ) + .addClass( 'js_field-state' ) + .val( value ); + $state.replaceWith( $newstate ); } // This event has a typo - deprecated in 2.5.0 From e3c2e4c094883d5b84dc3e0e97051c5ff9dac09d Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Sun, 1 Mar 2020 18:53:46 +0000 Subject: [PATCH 2/4] Update meta-boxes-order.js - add default text using .text() WC commit a2dee22 --- assets/js/admin/meta-boxes-order.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index 2d57cbe368..3ffb9c274d 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -54,12 +54,14 @@ jQuery( function ( $ ) { if ( ! $.isEmptyObject( wc_meta_boxes_order.states[ country ] ) ) { var state = wc_meta_boxes_order.states[ country ], + $defaultOption = $( '' ) + .text( woocommerce_admin_meta_boxes_order.i18n_select_state_text ), $newstate = $( '' ) .prop( 'id', input_id ) .prop( 'name', input_name ) .prop( 'placeholder', placeholder ) .addClass( 'js_field-state select short' ) - .append( $( '' ) ); + .append( $defaultOption ); $.each( state, function( index ) { var $option = $( '' ) From ac3c59632019d32b95ae80623ea3ba23ebb29c2f Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Sun, 1 Mar 2020 19:17:14 +0000 Subject: [PATCH 3/4] Update country-select.js WC Commit 0a10883 --- assets/js/frontend/country-select.js | 51 +++++++++++++++++----------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js index 9b5da36540..eca6eef3e7 100644 --- a/assets/js/frontend/country-select.js +++ b/assets/js/frontend/country-select.js @@ -97,43 +97,54 @@ jQuery( function( $ ) { if ( states[ country ] ) { if ( $.isEmptyObject( states[ country ] ) ) { - - $statebox.closest( 'p.form-row' ).hide().find( '.select2-container' ).remove(); - $statebox.replaceWith( '' ); - + var $newstate = $( '' ) + .prop( 'id', input_id ) + .prop( 'name', input_name ) + .prop( 'placeholder', placeholder ) + .addClass( 'hidden' ); + $parent.hide().find( '.select2-container' ).remove(); + $statebox.replaceWith( $newstate ); $( document.body ).trigger( 'country_to_state_changed', [ country, $wrapper ] ); } else { - - var options = '', - state = states[ country ]; - - for( var index in state ) { - if ( state.hasOwnProperty( index ) ) { - options = options + ''; - } - } + var state = states[ country ], + $defaultOption = $( '' ).text( wc_country_select_params.i18n_select_state_text ); $statebox.closest( 'p.form-row' ).show(); if ( $statebox.is( 'input' ) ) { - // Change for select - $statebox.replaceWith( '' ); + $newstate = $( '' ) + .prop( 'id', input_id ) + .prop( 'name', input_name ) + .data( 'placeholder', placeholder ) + .addClass( 'state_select' ); + $statebox.replaceWith( $newstate ); $statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' ); } - $statebox.html( '' + options ); + $statebox.empty().append( $defaultOption ); + + $.each( state, function( index ) { + var $option = $( '' ) + .prop( 'value', index ) + .text( state[ index ] ); + $statebox.append( $option ); + } ); + $statebox.val( value ).change(); $( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] ); } } else { - if ( $statebox.is( 'select' ) ) { - + if ( $statebox.is( 'select, input[type="hidden"]' ) ) { + var $newstate = $( '' ) + .prop( 'id', input_id ) + .prop( 'name', input_name ) + .prop( 'placeholder', placeholder ) + .addClass( 'input-text' ); $parent.show().find( '.select2-container' ).remove(); - $statebox.replaceWith( '' ); - + $statebox.replaceWith( $newstate ); $( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] ); } else if ( $statebox.is( 'input[type="hidden"]' ) ) { From a1011d565ea7fdb9fcc109eda73f1602bb62a76f Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Sun, 1 Mar 2020 19:40:43 +0000 Subject: [PATCH 4/4] Updates to country-select.js and meta-boxes-order.js WC commit 039915f "Version bump" --- assets/js/admin/meta-boxes-order.js | 12 +++++++----- assets/js/frontend/country-select.js | 8 ++++---- assets/js/frontend/country-select.min.js | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index 3ffb9c274d..d63a9014fc 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -43,7 +43,8 @@ jQuery( function ( $ ) { input_name = $state.attr( 'name' ), input_id = $state.attr( 'id' ), value = $this.data( 'woocommerce.stickState-' + country ) ? $this.data( 'woocommerce.stickState-' + country ) : $state.val(), - placeholder = $state.attr( 'placeholder' ); + placeholder = $state.attr( 'placeholder' ), + $newstate; if ( stickValue ){ $this.data( 'woocommerce.stickState-' + country, value ); @@ -55,7 +56,8 @@ jQuery( function ( $ ) { if ( ! $.isEmptyObject( wc_meta_boxes_order.states[ country ] ) ) { var state = wc_meta_boxes_order.states[ country ], $defaultOption = $( '' ) - .text( woocommerce_admin_meta_boxes_order.i18n_select_state_text ), + .text( woocommerce_admin_meta_boxes_order.i18n_select_state_text ); + $newstate = $( '' ) .prop( 'id', input_id ) .prop( 'name', input_name ) @@ -76,7 +78,7 @@ jQuery( function ( $ ) { $newstate.show().selectWoo().hide().change(); } else { - var $newstate = $( '' ) + $newstate = $( '' ) .prop( 'id', input_id ) .prop( 'name', input_name ) .prop( 'placeholder', placeholder ) @@ -655,7 +657,7 @@ jQuery( function ( $ ) { items: $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize(), security: woocommerce_admin_meta_boxes.calc_totals_nonce } ); - + $( document.body ).trigger( 'order-totals-recalculate-before', data ); $.ajax({ @@ -764,7 +766,7 @@ jQuery( function ( $ ) { $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { if ( true === response.success ) { // Redirect to same page for show the refunded status - window.location.href = window.location.href; + window.location.reload(); } else { window.alert( response.data.error ); wc_meta_boxes_order_items.reload_items(); diff --git a/assets/js/frontend/country-select.js b/assets/js/frontend/country-select.js index eca6eef3e7..11302787d8 100644 --- a/assets/js/frontend/country-select.js +++ b/assets/js/frontend/country-select.js @@ -93,11 +93,11 @@ jQuery( function( $ ) { input_name = $statebox.attr( 'name' ), input_id = $statebox.attr( 'id' ), value = $statebox.val(), - placeholder = $statebox.attr( 'placeholder' ) || $statebox.attr( 'data-placeholder' ) || ''; - + placeholder = $statebox.attr( 'placeholder' ) || $statebox.attr( 'data-placeholder' ) || '', + $newstate; if ( states[ country ] ) { if ( $.isEmptyObject( states[ country ] ) ) { - var $newstate = $( '' ) + $newstate = $( '' ) .prop( 'id', input_id ) .prop( 'name', input_name ) .prop( 'placeholder', placeholder ) @@ -138,7 +138,7 @@ jQuery( function( $ ) { } } else { if ( $statebox.is( 'select, input[type="hidden"]' ) ) { - var $newstate = $( '' ) + $newstate = $( '' ) .prop( 'id', input_id ) .prop( 'name', input_name ) .prop( 'placeholder', placeholder ) diff --git a/assets/js/frontend/country-select.min.js b/assets/js/frontend/country-select.min.js index ef358dfe5a..215498b70e 100644 --- a/assets/js/frontend/country-select.min.js +++ b/assets/js/frontend/country-select.min.js @@ -1 +1 @@ -jQuery(function(u){if("undefined"==typeof wc_country_select_params)return!1;if(u().selectWoo){var t=function(){u("select.country_select:visible, select.state_select:visible").each(function(){var t=u.extend({placeholderOption:"first",width:"100%"},{language:{errorLoading:function(){return wc_country_select_params.i18n_searching},inputTooLong:function(t){var e=t.input.length-t.maximum;return 1===e?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",e)},inputTooShort:function(t){var e=t.minimum-t.input.length;return 1===e?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",e)},loadingMore:function(){return wc_country_select_params.i18n_load_more},maximumSelected:function(t){return 1===t.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",t.maximum)},noResults:function(){return wc_country_select_params.i18n_no_matches},searching:function(){return wc_country_select_params.i18n_searching}}});u(this).selectWoo(t),u(this).on("select2:select",function(){u(this).focus()})})};t(),u(document.body).bind("country_to_state_changed",function(){t()})}var e=wc_country_select_params.countries.replace(/"/g,'"'),p=u.parseJSON(e);u(document.body).on("change","select.country_to_state, input.country_to_state",function(){var t=u(this).closest(".woocommerce-billing-fields, .woocommerce-shipping-fields, .woocommerce-shipping-calculator");t.length||(t=u(this).closest(".form-row").parent());var e=u(this).val(),n=t.find("#billing_state, #shipping_state, #calc_shipping_state"),o=n.closest("p.form-row"),c=n.attr("name"),i=n.attr("id"),r=n.val(),a=n.attr("placeholder")||n.attr("data-placeholder")||"";if(p[e])if(u.isEmptyObject(p[e]))n.closest("p.form-row").hide().find(".select2-container").remove(),n.replaceWith(''),u(document.body).trigger("country_to_state_changed",[e,t]);else{var s="",_=p[e];for(var l in _)_.hasOwnProperty(l)&&(s=s+'");n.closest("p.form-row").show(),n.is("input")&&(n.replaceWith(''),n=t.find("#billing_state, #shipping_state, #calc_shipping_state")),n.html('"+s),n.val(r).change(),u(document.body).trigger("country_to_state_changed",[e,t])}else n.is("select")?(o.show().find(".select2-container").remove(),n.replaceWith(''),u(document.body).trigger("country_to_state_changed",[e,t])):n.is('input[type="hidden"]')&&(o.show().find(".select2-container").remove(),n.replaceWith(''),u(document.body).trigger("country_to_state_changed",[e,t]));u(document.body).trigger("country_to_state_changing",[e,t])})}); \ No newline at end of file +jQuery(function(p){if("undefined"==typeof wc_country_select_params)return!1;if(p().selectWoo){var t=function(){p("select.country_select:visible, select.state_select:visible").each(function(){var t=p.extend({placeholder:p(this).attr("data-placeholder")||p(this).attr("placeholder")||"",width:"100%"},{language:{errorLoading:function(){return wc_country_select_params.i18n_searching},inputTooLong:function(t){var e=t.input.length-t.maximum;return 1===e?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",e)},inputTooShort:function(t){var e=t.minimum-t.input.length;return 1===e?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",e)},loadingMore:function(){return wc_country_select_params.i18n_load_more},maximumSelected:function(t){return 1===t.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",t.maximum)},noResults:function(){return wc_country_select_params.i18n_no_matches},searching:function(){return wc_country_select_params.i18n_searching}}});p(this).selectWoo(t),p(this).on("select2:select",function(){p(this).focus()})})};t(),p(document.body).bind("country_to_state_changed",function(){t()})}var e=wc_country_select_params.countries.replace(/"/g,'"'),u=p.parseJSON(e);p(document.body).on("change","select.country_to_state, input.country_to_state",function(){var t=p(this).closest(".woocommerce-billing-fields, .woocommerce-shipping-fields, .woocommerce-shipping-calculator");t.length||(t=p(this).closest(".form-row").parent());var e,n=p(this).val(),o=t.find("#billing_state, #shipping_state, #calc_shipping_state"),c=o.closest("p.form-row"),i=o.attr("name"),r=o.attr("id"),a=o.val(),s=o.attr("placeholder")||o.attr("data-placeholder")||"";if(u[n])if(p.isEmptyObject(u[n]))e=p('').prop("id",r).prop("name",i).prop("placeholder",s).addClass("hidden"),c.hide().find(".select2-container").remove(),o.replaceWith(e),p(document.body).trigger("country_to_state_changed",[n,t]);else{var _=u[n],l=p('').text(wc_country_select_params.i18n_select_state_text);o.closest("p.form-row").show(),o.is("input")&&(e=p("").prop("id",r).prop("name",i).data("placeholder",s).addClass("state_select"),o.replaceWith(e),o=t.find("#billing_state, #shipping_state, #calc_shipping_state")),o.empty().append(l),p.each(_,function(t){var e=p("").prop("value",t).text(_[t]);o.append(e)}),o.val(a).change(),p(document.body).trigger("country_to_state_changed",[n,t])}else o.is('select, input[type="hidden"]')?(e=p('').prop("id",r).prop("name",i).prop("placeholder",s).addClass("input-text"),c.show().find(".select2-container").remove(),o.replaceWith(e),p(document.body).trigger("country_to_state_changed",[n,t])):o.is('input[type="hidden"]')&&(c.show().find(".select2-container").remove(),o.replaceWith(''),p(document.body).trigger("country_to_state_changed",[n,t]));p(document.body).trigger("country_to_state_changing",[n,t])}))}; \ No newline at end of file