Work on shipping zone screens
This commit is contained in:
parent
0898060f49
commit
83cc0c7066
File diff suppressed because one or more lines are too long
|
@ -2268,23 +2268,114 @@ table.wc_shipping {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.wc-shipping-zone-settings {
|
||||||
|
th {
|
||||||
|
padding: 24px 24px 24px 0;
|
||||||
|
}
|
||||||
|
td.forminp {
|
||||||
|
padding: 15px 10px;
|
||||||
|
input, textarea {
|
||||||
|
padding: 8px;
|
||||||
|
width: 448px;
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
.wc-shipping-zone-region-select {
|
||||||
|
width: 448px;
|
||||||
|
max-width: 100% !important;
|
||||||
|
.select2-choices {
|
||||||
|
padding: 8px 8px 4px;
|
||||||
|
border-color: #DDDDDD;
|
||||||
|
min-height: 0;
|
||||||
|
line-height: 1;
|
||||||
|
input {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
margin: 0 4px 4px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.select2-container-active {
|
||||||
|
.select2-choices {
|
||||||
|
border-color: #777;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.wc-shipping-zone-postcodes-toggle {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.9em;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.wc-shipping-zone-postcodes-toggle + .wc-shipping-zone-postcodes {
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
.wc-shipping-zone-postcodes {
|
||||||
|
textarea {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
.description {
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-classes {
|
table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-classes {
|
||||||
td, th {
|
td, th {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
padding: 1em;
|
padding: 1em !important;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
li {
|
li {
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
.woocommerce-help-tip {
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
thead {
|
||||||
|
th {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.wc-shipping-zone-sort {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tbody td {
|
||||||
|
padding: 1.5em 1em !important;
|
||||||
|
}
|
||||||
|
th.remove {
|
||||||
|
width: 1%;
|
||||||
|
}
|
||||||
|
td.remove {
|
||||||
|
a {
|
||||||
|
width: 2em;
|
||||||
|
padding: 1em 0 0 0;
|
||||||
|
height: 0;
|
||||||
|
display: inline-block;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 1.25em;
|
||||||
|
position: relative;
|
||||||
|
&::before {
|
||||||
|
@include icon_dashicons( '\f335' );
|
||||||
|
position: absolute;
|
||||||
|
top:0;
|
||||||
|
right: 0;
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
&::before {
|
||||||
|
color: $red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
td.wc-shipping-zones-blank-state, td.wc-shipping-zone-method-blank-state {
|
td.wc-shipping-zones-blank-state, td.wc-shipping-zone-method-blank-state {
|
||||||
background: #f7f1f6 !important;
|
background: #f7f1f6 !important;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 7.5em 7.5%;
|
padding: 7.5em 7.5% !important;
|
||||||
border-bottom: 2px solid #eee2ec;
|
border-bottom: 2px solid #eee2ec;
|
||||||
p, li {
|
p, li {
|
||||||
color: #a46497;
|
color: #a46497;
|
||||||
|
@ -2403,22 +2494,6 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
|
||||||
a.wc-shipping-zone-delete:hover, a.wc-shipping-class-delete:hover {
|
a.wc-shipping-zone-delete:hover, a.wc-shipping-class-delete:hover {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
.wc-shipping-zone-postcodes-toggle {
|
|
||||||
float: right;
|
|
||||||
margin: 0;
|
|
||||||
font-size: 0.9em;
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
.wc-shipping-zone-postcodes {
|
|
||||||
display:none;
|
|
||||||
textarea {
|
|
||||||
margin-top: 1em;
|
|
||||||
}
|
|
||||||
.description {
|
|
||||||
font-size: 0.9em;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.wc-shipping-class-count {
|
.wc-shipping-class-count {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
@ -2439,18 +2514,9 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
|
||||||
li::before {
|
li::before {
|
||||||
content: ', ';
|
content: ', ';
|
||||||
}
|
}
|
||||||
li:first-child::before,
|
li:first-child::before {
|
||||||
li:nth-child( 2 )::before {
|
|
||||||
content: '';
|
content: '';
|
||||||
}
|
}
|
||||||
li:first-child {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
li.wc-shipping-zone-methods-add-row {
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.add_shipping_method {
|
.add_shipping_method {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
|
@ -21,19 +21,24 @@
|
||||||
this.trigger( 'change:methods' );
|
this.trigger( 'change:methods' );
|
||||||
},
|
},
|
||||||
save: function() {
|
save: function() {
|
||||||
if ( _.size( this.changes ) ) {
|
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_methods_save_changes', {
|
||||||
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_methods_save_changes', {
|
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
||||||
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
changes : this.changes,
|
||||||
changes : this.changes,
|
zone_name : $('#zone_name').val(),
|
||||||
zone_id : data.zone_id
|
zone_locations : $('#zone_locations').val(),
|
||||||
}, this.onSaveResponse, 'json' );
|
zone_postcodes : $('#zone_postcodes').val(),
|
||||||
} else {
|
zone_id : data.zone_id
|
||||||
shippingMethod.trigger( 'saved:methods' );
|
}, this.onSaveResponse, 'json' );
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onSaveResponse: function( response, textStatus ) {
|
onSaveResponse: function( response, textStatus ) {
|
||||||
if ( 'success' === textStatus ) {
|
if ( 'success' === textStatus ) {
|
||||||
if ( response.success ) {
|
if ( response.success ) {
|
||||||
|
if ( response.data.zone_id !== data.zone_id ) {
|
||||||
|
data.zone_id = response.data.zone_id;
|
||||||
|
if ( window.history.pushState ) {
|
||||||
|
window.history.pushState({}, '', 'admin.php?page=wc-settings&tab=shipping&zone_id=' + response.data.zone_id );
|
||||||
|
}
|
||||||
|
}
|
||||||
shippingMethod.set( 'methods', response.data.methods );
|
shippingMethod.set( 'methods', response.data.methods );
|
||||||
shippingMethod.trigger( 'change:methods' );
|
shippingMethod.trigger( 'change:methods' );
|
||||||
shippingMethod.changes = {};
|
shippingMethod.changes = {};
|
||||||
|
@ -57,12 +62,21 @@
|
||||||
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||||
$save_button.on( 'click', { view: this }, this.onSubmit );
|
$save_button.on( 'click', { view: this }, this.onSubmit );
|
||||||
|
|
||||||
// Settings modals
|
$( document.body ).on( 'input', '#zone_name', { view: this }, this.onUpdateZoneName );
|
||||||
|
$( document.body ).on( 'input', '#zone_locations, #zone_postcodes', { view: this }, this.onUpdateZone );
|
||||||
$( document.body ).on( 'click', '.wc-shipping-zone-method-settings', { view: this }, this.onConfigureShippingMethod );
|
$( document.body ).on( 'click', '.wc-shipping-zone-method-settings', { view: this }, this.onConfigureShippingMethod );
|
||||||
$( document.body ).on( 'click', '.wc-shipping-zone-add-method', { view: this }, this.onAddShippingMethod );
|
$( document.body ).on( 'click', '.wc-shipping-zone-add-method', { view: this }, this.onAddShippingMethod );
|
||||||
$( document.body ).on( 'wc_backbone_modal_response', this.onConfigureShippingMethodSubmitted );
|
$( document.body ).on( 'wc_backbone_modal_response', this.onConfigureShippingMethodSubmitted );
|
||||||
$( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted );
|
$( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted );
|
||||||
$( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector );
|
$( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector );
|
||||||
|
$( document.body ).on( 'click', '.wc-shipping-zone-postcodes-toggle', this.onTogglePostcodes );
|
||||||
|
},
|
||||||
|
onUpdateZone: function() {
|
||||||
|
shippingMethod.trigger( 'change:methods' );
|
||||||
|
},
|
||||||
|
onUpdateZoneName: function() {
|
||||||
|
$('.wc-shipping-zone-name').text( $( this ).val() );
|
||||||
|
shippingMethod.trigger( 'change:methods' );
|
||||||
},
|
},
|
||||||
block: function() {
|
block: function() {
|
||||||
$( this.el ).block({
|
$( this.el ).block({
|
||||||
|
@ -300,6 +314,12 @@
|
||||||
zone_id : data.zone_id
|
zone_id : data.zone_id
|
||||||
}, function( response, textStatus ) {
|
}, function( response, textStatus ) {
|
||||||
if ( 'success' === textStatus && response.success ) {
|
if ( 'success' === textStatus && response.success ) {
|
||||||
|
if ( response.data.zone_id !== data.zone_id ) {
|
||||||
|
data.zone_id = response.data.zone_id;
|
||||||
|
if ( window.history.pushState ) {
|
||||||
|
window.history.pushState({}, '', 'admin.php?page=wc-settings&tab=shipping&zone_id=' + response.data.zone_id );
|
||||||
|
}
|
||||||
|
}
|
||||||
// Trigger save if there are changes, or just re-render
|
// Trigger save if there are changes, or just re-render
|
||||||
if ( _.size( shippingMethodView.model.changes ) ) {
|
if ( _.size( shippingMethodView.model.changes ) ) {
|
||||||
shippingMethodView.model.save();
|
shippingMethodView.model.save();
|
||||||
|
@ -319,6 +339,12 @@
|
||||||
$( this ).parent().find( '.wc-shipping-zone-method-description' ).remove();
|
$( this ).parent().find( '.wc-shipping-zone-method-description' ).remove();
|
||||||
$( this ).after( '<p class="wc-shipping-zone-method-description">' + description + '</p>' );
|
$( this ).after( '<p class="wc-shipping-zone-method-description">' + description + '</p>' );
|
||||||
$( this ).closest( 'article' ).height( $( this ).parent().height() );
|
$( this ).closest( 'article' ).height( $( this ).parent().height() );
|
||||||
|
},
|
||||||
|
onTogglePostcodes: function( event ) {
|
||||||
|
event.preventDefault();
|
||||||
|
var $tr = $( this ).closest( 'tr');
|
||||||
|
$tr.find( '.wc-shipping-zone-postcodes' ).show();
|
||||||
|
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
|
||||||
}
|
}
|
||||||
} ),
|
} ),
|
||||||
shippingMethod = new ShippingMethod({
|
shippingMethod = new ShippingMethod({
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
||||||
/* global wc_enhanced_select_params, shippingZonesLocalizeScript, ajaxurl */
|
/* global shippingZonesLocalizeScript, ajaxurl */
|
||||||
( function( $, data, wp, ajaxurl ) {
|
( function( $, data, wp, ajaxurl ) {
|
||||||
$( function() {
|
$( function() {
|
||||||
var $table = $( '.wc-shipping-zones' ),
|
var $table = $( '.wc-shipping-zones' ),
|
||||||
|
@ -6,14 +6,6 @@
|
||||||
$save_button = $( '.wc-shipping-zone-save' ),
|
$save_button = $( '.wc-shipping-zone-save' ),
|
||||||
$row_template = wp.template( 'wc-shipping-zone-row' ),
|
$row_template = wp.template( 'wc-shipping-zone-row' ),
|
||||||
$blank_template = wp.template( 'wc-shipping-zone-row-blank' ),
|
$blank_template = wp.template( 'wc-shipping-zone-row-blank' ),
|
||||||
select2_args = $.extend({
|
|
||||||
minimumResultsForSearch: 10,
|
|
||||||
allowClear: $( this ).data( 'allow_clear' ) ? true : false,
|
|
||||||
placeholder: $( this ).data( 'placeholder' ),
|
|
||||||
matcher: function( term, text, opt ) {
|
|
||||||
return text.toUpperCase().indexOf( term.toUpperCase() ) >= 0 || opt.attr( 'alt' ).toUpperCase().indexOf( term.toUpperCase() ) >= 0;
|
|
||||||
}
|
|
||||||
}, getEnhancedSelectFormatString() ),
|
|
||||||
|
|
||||||
// Backbone model
|
// Backbone model
|
||||||
ShippingZone = Backbone.Model.extend({
|
ShippingZone = Backbone.Model.extend({
|
||||||
|
@ -88,10 +80,7 @@
|
||||||
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
|
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
|
||||||
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||||
$save_button.on( 'click', { view: this }, this.onSubmit );
|
$save_button.on( 'click', { view: this }, this.onSubmit );
|
||||||
$( document.body ).on( 'click', '.add_shipping_method:not(.disabled)', { view: this }, this.onAddShippingMethod );
|
|
||||||
$( document.body ).on( 'click', '.wc-shipping-zone-add', { view: this }, this.onAddNewRow );
|
$( document.body ).on( 'click', '.wc-shipping-zone-add', { view: this }, this.onAddNewRow );
|
||||||
$( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted );
|
|
||||||
$( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector );
|
|
||||||
},
|
},
|
||||||
block: function() {
|
block: function() {
|
||||||
$( this.el ).block({
|
$( this.el ).block({
|
||||||
|
@ -137,57 +126,9 @@
|
||||||
var view = this;
|
var view = this;
|
||||||
var $tr = view.$el.find( 'tr[data-id="' + rowData.zone_id + '"]');
|
var $tr = view.$el.find( 'tr[data-id="' + rowData.zone_id + '"]');
|
||||||
|
|
||||||
// Select values in region select
|
|
||||||
_.each( rowData.zone_locations, function( location ) {
|
|
||||||
if ( 'string' === jQuery.type( location ) ) {
|
|
||||||
$tr.find( 'option[value="' + location + '"]' ).prop( 'selected', true );
|
|
||||||
} else {
|
|
||||||
if ( 'postcode' === location.type ) {
|
|
||||||
var postcode_field = $tr.find( '.wc-shipping-zone-postcodes :input' );
|
|
||||||
|
|
||||||
if ( postcode_field.val() ) {
|
|
||||||
postcode_field.val( postcode_field.val() + '\n' + location.code );
|
|
||||||
} else {
|
|
||||||
postcode_field.val( location.code );
|
|
||||||
}
|
|
||||||
$tr.find( '.wc-shipping-zone-postcodes' ).show();
|
|
||||||
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
|
|
||||||
} else {
|
|
||||||
$tr.find( 'option[value="' + location.type + ':' + location.code + '"]' ).prop( 'selected', true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
if ( rowData.zone_postcodes ) {
|
|
||||||
_.each( rowData.zone_postcodes, function( location ) {
|
|
||||||
var postcode_field = $tr.find( '.wc-shipping-zone-postcodes :input' );
|
|
||||||
|
|
||||||
if ( postcode_field.val() ) {
|
|
||||||
postcode_field.val( postcode_field.val() + '\n' + location.code );
|
|
||||||
} else {
|
|
||||||
postcode_field.val( location.code );
|
|
||||||
}
|
|
||||||
$tr.find( '.wc-shipping-zone-postcodes' ).show();
|
|
||||||
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
// List shipping methods
|
// List shipping methods
|
||||||
view.renderShippingMethods( rowData.zone_id, rowData.shipping_methods );
|
view.renderShippingMethods( rowData.zone_id, rowData.shipping_methods );
|
||||||
|
|
||||||
// Make the row function
|
|
||||||
$tr.find( '.view' ).show();
|
|
||||||
$tr.find( '.edit' ).hide();
|
|
||||||
$tr.find( '.wc-shipping-zone-edit' ).on( 'click', { view: this }, this.onEditRow );
|
|
||||||
$tr.find( '.wc-shipping-zone-cancel-edit' ).on( 'click', { view: this }, this.onCancelEditRow );
|
|
||||||
$tr.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow );
|
$tr.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||||
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes );
|
|
||||||
|
|
||||||
// Editing?
|
|
||||||
if ( true === rowData.editing ) {
|
|
||||||
$tr.addClass( 'editing' );
|
|
||||||
$tr.find( '.wc-shipping-zone-edit' ).trigger( 'click' );
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
initRows: function() {
|
initRows: function() {
|
||||||
// Stripe
|
// Stripe
|
||||||
|
@ -196,7 +137,6 @@
|
||||||
} else {
|
} else {
|
||||||
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
|
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tooltips
|
// Tooltips
|
||||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||||
|
@ -231,73 +171,6 @@
|
||||||
event.data.view.model.save();
|
event.data.view.model.save();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
},
|
},
|
||||||
onAddNewRow: function( event ) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
var view = event.data.view,
|
|
||||||
model = view.model,
|
|
||||||
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
|
|
||||||
changes = {},
|
|
||||||
size = _.size( zones ),
|
|
||||||
newRow = _.extend( {}, data.default_zone, {
|
|
||||||
zone_id : 'new-' + size + '-' + Date.now(),
|
|
||||||
editing : true
|
|
||||||
} );
|
|
||||||
|
|
||||||
$( '.wc-shipping-zones-blank-state' ).closest( 'tr' ).remove();
|
|
||||||
|
|
||||||
newRow.zone_order = 1 + _.max(
|
|
||||||
_.pluck( zones, 'zone_order' ),
|
|
||||||
function ( val ) {
|
|
||||||
// Cast them all to integers, because strings compare funky. Sighhh.
|
|
||||||
return parseInt( val, 10 );
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
changes[ newRow.zone_id ] = newRow;
|
|
||||||
|
|
||||||
model.logChanges( changes );
|
|
||||||
view.renderRow( newRow );
|
|
||||||
view.initRows();
|
|
||||||
},
|
|
||||||
onTogglePostcodes: function( event ) {
|
|
||||||
event.preventDefault();
|
|
||||||
var $tr = $( this ).closest( 'tr');
|
|
||||||
$tr.find( '.wc-shipping-zone-postcodes' ).show();
|
|
||||||
$tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide();
|
|
||||||
},
|
|
||||||
onEditRow: function( event ) {
|
|
||||||
event.preventDefault();
|
|
||||||
event.data.view.model.trigger( 'change:zones' );
|
|
||||||
$( this ).closest('tr').addClass( 'editing' );
|
|
||||||
$( this ).closest('tr').find('.view').hide();
|
|
||||||
$( this ).closest('tr').find('.edit').show();
|
|
||||||
$( '.wc-shipping-zone-region-select:not(.enhanced)' ).select2( select2_args );
|
|
||||||
$( '.wc-shipping-zone-region-select:not(.enhanced)' ).addClass('enhanced');
|
|
||||||
|
|
||||||
var addShippingMethod = $( this ).closest('tr').find('.add_shipping_method');
|
|
||||||
addShippingMethod.addClass( 'disabled' );
|
|
||||||
addShippingMethod.tipTip({ 'attribute': 'data-disabled-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 });
|
|
||||||
},
|
|
||||||
onCancelEditRow: function( event ) {
|
|
||||||
var view = event.data.view,
|
|
||||||
model = view.model,
|
|
||||||
row = $( this ).closest('tr'),
|
|
||||||
zone_id = row.data('id'),
|
|
||||||
zones = _.indexBy( model.get( 'zones' ), 'zone_id' );
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
model.discardChanges( zone_id );
|
|
||||||
|
|
||||||
if ( zones[ zone_id ] ) {
|
|
||||||
zones[ zone_id ].editing = false;
|
|
||||||
row.after( view.rowTemplate( zones[ zone_id ] ) );
|
|
||||||
view.initRow( zones[ zone_id ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
row.remove();
|
|
||||||
view.initRows();
|
|
||||||
},
|
|
||||||
onDeleteRow: function( event ) {
|
onDeleteRow: function( event ) {
|
||||||
var view = event.data.view,
|
var view = event.data.view,
|
||||||
model = view.model,
|
model = view.model,
|
||||||
|
@ -374,44 +247,6 @@
|
||||||
if ( _.size( changes ) ) {
|
if ( _.size( changes ) ) {
|
||||||
model.logChanges( changes );
|
model.logChanges( changes );
|
||||||
}
|
}
|
||||||
},
|
|
||||||
onAddShippingMethod: function( event ) {
|
|
||||||
var zone_id = $( this ).closest('tr').data('id');
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
$( this ).WCBackboneModal({
|
|
||||||
template : 'wc-modal-add-shipping-method',
|
|
||||||
variable : {
|
|
||||||
zone_id : zone_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$( '.wc-shipping-zone-method-selector select' ).change();
|
|
||||||
},
|
|
||||||
onAddShippingMethodSubmitted: function( event, target, posted_data ) {
|
|
||||||
if ( 'wc-modal-add-shipping-method' === target ) {
|
|
||||||
shippingZoneView.block();
|
|
||||||
|
|
||||||
// Add method to zone via ajax call
|
|
||||||
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_add_method', {
|
|
||||||
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
|
|
||||||
method_id : posted_data.add_method_id,
|
|
||||||
zone_id : posted_data.zone_id
|
|
||||||
}, function( response, textStatus ) {
|
|
||||||
if ( 'success' === textStatus && response.success ) {
|
|
||||||
// Method was added. Render methods.
|
|
||||||
shippingZoneView.renderShippingMethods( posted_data.zone_id, response.data.methods );
|
|
||||||
}
|
|
||||||
shippingZoneView.unblock();
|
|
||||||
}, 'json' );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onChangeShippingMethodSelector: function() {
|
|
||||||
var description = $( this ).find( 'option:selected' ).data( 'description' );
|
|
||||||
$( this ).parent().find( '.wc-shipping-zone-method-description' ).remove();
|
|
||||||
$( this ).after( '<p class="wc-shipping-zone-method-description">' + description + '</p>' );
|
|
||||||
$( this ).closest( 'article' ).height( $( this ).parent().height() );
|
|
||||||
}
|
}
|
||||||
} ),
|
} ),
|
||||||
shippingZone = new ShippingZone({
|
shippingZone = new ShippingZone({
|
||||||
|
@ -431,55 +266,5 @@
|
||||||
handle: 'td.wc-shipping-zone-sort',
|
handle: 'td.wc-shipping-zone-sort',
|
||||||
scrollSensitivity: 40
|
scrollSensitivity: 40
|
||||||
});
|
});
|
||||||
|
|
||||||
function getEnhancedSelectFormatString() {
|
|
||||||
var formatString = {
|
|
||||||
formatMatches: function( matches ) {
|
|
||||||
if ( 1 === matches ) {
|
|
||||||
return wc_enhanced_select_params.i18n_matches_1;
|
|
||||||
}
|
|
||||||
return wc_enhanced_select_params.i18n_matches_n.replace( '%qty%', matches );
|
|
||||||
},
|
|
||||||
formatNoMatches: function() {
|
|
||||||
return wc_enhanced_select_params.i18n_no_matches;
|
|
||||||
},
|
|
||||||
formatAjaxError: function() {
|
|
||||||
return wc_enhanced_select_params.i18n_ajax_error;
|
|
||||||
},
|
|
||||||
formatInputTooShort: function( input, min ) {
|
|
||||||
var number = min - input.length;
|
|
||||||
|
|
||||||
if ( 1 === number ) {
|
|
||||||
return wc_enhanced_select_params.i18n_input_too_short_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wc_enhanced_select_params.i18n_input_too_short_n.replace( '%qty%', number );
|
|
||||||
},
|
|
||||||
formatInputTooLong: function( input, max ) {
|
|
||||||
var number = input.length - max;
|
|
||||||
|
|
||||||
if ( 1 === number ) {
|
|
||||||
return wc_enhanced_select_params.i18n_input_too_long_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wc_enhanced_select_params.i18n_input_too_long_n.replace( '%qty%', number );
|
|
||||||
},
|
|
||||||
formatSelectionTooBig: function( limit ) {
|
|
||||||
if ( 1 === limit ) {
|
|
||||||
return wc_enhanced_select_params.i18n_selection_too_long_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wc_enhanced_select_params.i18n_selection_too_long_n.replace( '%qty%', limit );
|
|
||||||
},
|
|
||||||
formatLoadMore: function() {
|
|
||||||
return wc_enhanced_select_params.i18n_load_more;
|
|
||||||
},
|
|
||||||
formatSearching: function() {
|
|
||||||
return wc_enhanced_select_params.i18n_searching;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return formatString;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
})( jQuery, shippingZonesLocalizeScript, wp, ajaxurl );
|
})( jQuery, shippingZonesLocalizeScript, wp, ajaxurl );
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -190,7 +190,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
||||||
|
|
||||||
if ( isset( $_REQUEST['zone_id'] ) ) {
|
if ( isset( $_REQUEST['zone_id'] ) ) {
|
||||||
$hide_save_button = true;
|
$hide_save_button = true;
|
||||||
$this->zone_methods_screen( absint( $_REQUEST['zone_id'] ) );
|
$this->zone_methods_screen( wc_clean( $_REQUEST['zone_id'] ) );
|
||||||
} elseif ( isset( $_REQUEST['instance_id'] ) ) {
|
} elseif ( isset( $_REQUEST['instance_id'] ) ) {
|
||||||
$this->instance_settings_screen( absint( $_REQUEST['instance_id'] ) );
|
$this->instance_settings_screen( absint( $_REQUEST['instance_id'] ) );
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,16 +204,37 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
||||||
* @param int $zone_id
|
* @param int $zone_id
|
||||||
*/
|
*/
|
||||||
protected function zone_methods_screen( $zone_id ) {
|
protected function zone_methods_screen( $zone_id ) {
|
||||||
$wc_shipping = WC_Shipping ::instance();
|
if ( 'new' === $zone_id ) {
|
||||||
$zone = WC_Shipping_Zones::get_zone( $zone_id );
|
$zone = new WC_Shipping_Zone();
|
||||||
$shipping_methods = $wc_shipping->get_shipping_methods();
|
$zone->set_zone_name( __( 'New Zone', 'woocommerce' ) );
|
||||||
|
} else {
|
||||||
|
$zone = WC_Shipping_Zones::get_zone( $zone_id );
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! $zone ) {
|
if ( ! $zone ) {
|
||||||
wp_die( __( 'Zone does not exist!', 'woocommerce' ) );
|
wp_die( __( 'Zone does not exist!', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$allowed_countries = WC()->countries->get_allowed_countries();
|
||||||
|
$wc_shipping = WC_Shipping ::instance();
|
||||||
|
$shipping_methods = $wc_shipping->get_shipping_methods();
|
||||||
|
$continents = WC()->countries->get_continents();
|
||||||
|
|
||||||
|
// Prepare locations
|
||||||
|
$locations = array();
|
||||||
|
$postcodes = array();
|
||||||
|
|
||||||
|
foreach ( $zone->get_zone_locations() as $location ) {
|
||||||
|
if ( 'postcode' === $location->type ) {
|
||||||
|
$postcodes[] = $location->code;
|
||||||
|
} else {
|
||||||
|
$locations[] = $location->type . ':' . $location->code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wp_localize_script( 'wc-shipping-zone-methods', 'shippingZoneMethodsLocalizeScript', array(
|
wp_localize_script( 'wc-shipping-zone-methods', 'shippingZoneMethodsLocalizeScript', array(
|
||||||
'methods' => $zone->get_shipping_methods(),
|
'methods' => $zone->get_shipping_methods(),
|
||||||
|
'zone_name' => $zone->get_zone_name(),
|
||||||
'zone_id' => $zone->get_zone_id(),
|
'zone_id' => $zone->get_zone_id(),
|
||||||
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
|
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
|
||||||
'strings' => array(
|
'strings' => array(
|
||||||
|
|
|
@ -6,36 +6,93 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
<a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=shipping' ); ?>"><?php _e( 'Shipping Zones', 'woocommerce' ); ?></a> >
|
<a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=shipping' ); ?>"><?php _e( 'Shipping Zones', 'woocommerce' ); ?></a> >
|
||||||
<?php echo esc_html( $zone->get_zone_name() ); ?>
|
<span class="wc-shipping-zone-name"><?php echo esc_html( $zone->get_zone_name() ); ?></span>
|
||||||
<?php echo wc_help_tip( __( 'The following shipping methods apply to customers with shipping addresses within this zone.', 'woocommerce' ) ); ?>
|
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<?php do_action( 'woocommerce_shipping_zone_before_methods_table' ); ?>
|
<?php do_action( 'woocommerce_shipping_zone_before_methods_table' ); ?>
|
||||||
|
|
||||||
<table class="wc-shipping-zone-methods widefat">
|
<table class="form-table wc-shipping-zone-settings">
|
||||||
<thead>
|
<tbody>
|
||||||
<tr>
|
<tr valign="top" class="">
|
||||||
<th class="wc-shipping-zone-method-sort"><?php echo wc_help_tip( __( 'Drag and drop to re-order your shipping methods. This is the order in which they will display during checkout.', 'woocommerce' ) ); ?></th>
|
<th scope="row" class="titledesc">
|
||||||
<th class="wc-shipping-zone-method-title"><?php esc_html_e( 'Title', 'woocommerce' ); ?></th>
|
<label for="zone_name"><?php esc_html_e( 'Zone Name', 'woocommerce' ); ?></label>
|
||||||
<th class="wc-shipping-zone-method-enabled"><?php esc_html_e( 'Enabled', 'woocommerce' ); ?></th>
|
<?php echo wc_help_tip( __( 'This is the name of the zone for your reference.', 'woocommerce' ) ); ?>
|
||||||
<th class="wc-shipping-zone-method-type"><?php esc_html_e( 'Type', 'woocommerce' ); ?></th>
|
</th>
|
||||||
<th class="wc-shipping-zone-method-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
|
<td class="forminp">
|
||||||
</tr>
|
<input type="text" name="zone_name" id="zone_name" value="<?php echo esc_attr( $zone->get_zone_name() ); ?>" placeholder="<?php _e( 'Zone Name', 'woocommerce' ); ?>">
|
||||||
</thead>
|
|
||||||
<tfoot>
|
|
||||||
<tr>
|
|
||||||
<td colspan="5">
|
|
||||||
<input type="submit" name="save" class="button button-primary wc-shipping-zone-method-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled />
|
|
||||||
<input type="submit" class="button button-secondary wc-shipping-zone-add-method" value="<?php esc_attr_e( 'Add shipping method', 'woocommerce' ); ?>" />
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
<tr valign="top" class="">
|
||||||
<tbody class="wc-shipping-zone-method-rows"></tbody>
|
<th scope="row" class="titledesc">
|
||||||
|
<label for="zone_locations"><?php esc_html_e( 'Zone Region(s)', 'woocommerce' ); ?></label>
|
||||||
|
<?php echo wc_help_tip( __( 'These are regions inside this zone. Customers will be matched against these regions.', 'woocommerce' ) ); ?>
|
||||||
|
</th>
|
||||||
|
<td class="forminp">
|
||||||
|
<select multiple="multiple" id="zone_locations" name="zone_locations" data-placeholder="<?php _e( 'Select regions within this zone', 'woocommerce' ); ?>" class="wc-shipping-zone-region-select chosen_select">
|
||||||
|
<?php
|
||||||
|
foreach ( $continents as $continent_code => $continent ) {
|
||||||
|
echo '<option value="continent:' . esc_attr( $continent_code ) . '" ' . selected( in_array( "continent:$continent_code", $locations ), true, false ) . ' alt="">' . esc_html( $continent['name'] ) . '</option>';
|
||||||
|
|
||||||
|
$countries = array_intersect( array_keys( $allowed_countries ), $continent['countries'] );
|
||||||
|
|
||||||
|
foreach ( $countries as $country_code ) {
|
||||||
|
echo '<option value="country:' . esc_attr( $country_code ) . '" ' . selected( in_array( "country:$country_code", $locations ), true, false ) . ' alt="' . esc_attr( $continent['name'] ) . '">' . esc_html( ' ' . $allowed_countries[ $country_code ] ) . '</option>';
|
||||||
|
|
||||||
|
if ( $states = WC()->countries->get_states( $country_code ) ) {
|
||||||
|
foreach ( $states as $state_code => $state_name ) {
|
||||||
|
echo '<option value="state:' . esc_attr( $country_code . ':' . $state_code ) . '" ' . selected( in_array( "state:$country_code:$state_code", $locations ), true, false ) . ' alt="' . esc_attr( $continent['name'] . ' ' . $allowed_countries[ $country_code ] ) . '">' . esc_html( ' ' . $state_name ) . '</option>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?php if ( empty( $postcodes ) ) : ?>
|
||||||
|
<a class="wc-shipping-zone-postcodes-toggle" href="#"><?php _e( 'Limit to specific ZIP/postcodes', 'woocommerce' ); ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div class="wc-shipping-zone-postcodes">
|
||||||
|
<textarea name="zone_postcodes" id="zone_postcodes" placeholder="<?php esc_attr_e( 'List 1 postcode per line', 'woocommerce' ); ?>" class="input-text large-text" cols="25" rows="5"><?php echo esc_textarea( implode( "\n", $postcodes ) ); ?></textarea>
|
||||||
|
<span class="description"><?php _e( 'Postcodes containing wildcards (e.g. CB23*) and fully numeric ranges (e.g. <code>90210...99000</code>) are also supported.', 'woocommerce' ) ?></span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr valign="top" class="">
|
||||||
|
<th scope="row" class="titledesc">
|
||||||
|
<label><?php esc_html_e( 'Shipping Method(s)', 'woocommerce' ); ?></label>
|
||||||
|
<?php echo wc_help_tip( __( 'The following shipping methods apply to customers with shipping addresses within this zone.', 'woocommerce' ) ); ?>
|
||||||
|
</th>
|
||||||
|
<td class="">
|
||||||
|
<table class="wc-shipping-zone-methods widefat">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="wc-shipping-zone-method-sort"><?php echo wc_help_tip( __( 'Drag and drop to re-order your shipping methods. This is the order in which they will display during checkout.', 'woocommerce' ) ); ?></th>
|
||||||
|
<th class="wc-shipping-zone-method-title"><?php esc_html_e( 'Title', 'woocommerce' ); ?></th>
|
||||||
|
<th class="wc-shipping-zone-method-type"><?php esc_html_e( 'Type', 'woocommerce' ); ?></th>
|
||||||
|
<th class="wc-shipping-zone-method-enabled"><?php esc_html_e( 'Enabled', 'woocommerce' ); ?></th>
|
||||||
|
<th class="wc-shipping-zone-method-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
|
||||||
|
<th class="remove"> </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6">
|
||||||
|
<input type="submit" class="button wc-shipping-zone-add-method" value="<?php esc_attr_e( 'Add shipping method', 'woocommerce' ); ?>" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody class="wc-shipping-zone-method-rows"></tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<p class="submit">
|
||||||
|
<input type="submit" name="submit" id="submit" class="button button-primary button-hero wc-shipping-zone-method-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled />
|
||||||
|
</p>
|
||||||
|
|
||||||
<script type="text/html" id="tmpl-wc-shipping-zone-method-row-blank">
|
<script type="text/html" id="tmpl-wc-shipping-zone-method-row-blank">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="wc-shipping-zone-method-blank-state" colspan="5">
|
<td class="wc-shipping-zone-method-blank-state" colspan="6">
|
||||||
<p class="main"><?php _e( 'Add shipping methods to this zone', 'woocommerce' ); ?></p>
|
<p class="main"><?php _e( 'Add shipping methods to this zone', 'woocommerce' ); ?></p>
|
||||||
<p><?php _e( 'You can add multiple shipping methods within this zone. Only customers within the zone will see them.', 'woocommerce' ); ?></p>
|
<p><?php _e( 'You can add multiple shipping methods within this zone. Only customers within the zone will see them.', 'woocommerce' ); ?></p>
|
||||||
<p><?php _e( 'Click "Add shipping method" to get started.', 'woocommerce' ); ?></p>
|
<p><?php _e( 'Click "Add shipping method" to get started.', 'woocommerce' ); ?></p>
|
||||||
|
@ -48,13 +105,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
<td width="1%" class="wc-shipping-zone-method-sort"></td>
|
<td width="1%" class="wc-shipping-zone-method-sort"></td>
|
||||||
<td class="wc-shipping-zone-method-title">
|
<td class="wc-shipping-zone-method-title">
|
||||||
<a class="wc-shipping-zone-method-settings" href="admin.php?page=wc-settings&tab=shipping&instance_id={{ data.instance_id }}">{{ data.title }}</a>
|
<a class="wc-shipping-zone-method-settings" href="admin.php?page=wc-settings&tab=shipping&instance_id={{ data.instance_id }}">{{ data.title }}</a>
|
||||||
<div class="row-actions">
|
|
||||||
<a class="wc-shipping-zone-method-settings" href="admin.php?page=wc-settings&tab=shipping&instance_id={{ data.instance_id }}"><?php _e( 'Settings', 'woocommerce' ); ?></a> | <a href="#" class="wc-shipping-zone-method-delete"><?php _e( 'Remove', 'woocommerce' ); ?></a>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
<td width="1%" class="wc-shipping-zone-method-enabled"><a href="#">{{{ data.enabled_icon }}}</a></td>
|
|
||||||
<td class="wc-shipping-zone-method-type">{{ data.method_title }}</td>
|
<td class="wc-shipping-zone-method-type">{{ data.method_title }}</td>
|
||||||
|
<td width="1%" class="wc-shipping-zone-method-enabled"><a href="#">{{{ data.enabled_icon }}}</a></td>
|
||||||
<td class="wc-shipping-zone-method-description">{{ data.method_description }}</td>
|
<td class="wc-shipping-zone-method-description">{{ data.method_description }}</td>
|
||||||
|
<td class="remove"><a href="#" class="wc-shipping-zone-method-delete"><?php _e( 'Remove', 'woocommerce' ); ?></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
<?php _e( 'Shipping Zones', 'woocommerce' ); ?>
|
<?php _e( 'Shipping Zones', 'woocommerce' ); ?>
|
||||||
<?php echo wc_help_tip( __( 'A shipping zone is a geographic region where a certain set of shipping methods and rates apply.', 'woocommerce' ) . ' ' . __( 'WooCommerce will automatically choose the correct shipping zone based on your customer‘s shipping address and present the shipping methods within that zone to them.', 'woocommerce' ) ); ?>
|
<a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=new' ); ?>" class="page-title-action"><?php esc_html_e( 'Add shipping zone', 'woocommerce' ); ?></a>
|
||||||
</h2>
|
</h2>
|
||||||
|
<p><?php echo __( 'A shipping zone is a geographic region where a certain set of shipping methods are offered.', 'woocommerce' ) . ' ' . __( 'WooCommerce will match a customer to a single zone using their shipping address and present the shipping methods within that zone to them.', 'woocommerce' ); ?></p>
|
||||||
<table class="wc-shipping-zones widefat">
|
<table class="wc-shipping-zones widefat">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -16,13 +16,13 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
<th class="wc-shipping-zone-name"><?php esc_html_e( 'Zone Name', 'woocommerce' ); ?></th>
|
<th class="wc-shipping-zone-name"><?php esc_html_e( 'Zone Name', 'woocommerce' ); ?></th>
|
||||||
<th class="wc-shipping-zone-region"><?php esc_html_e( 'Region(s)', 'woocommerce' ); ?></th>
|
<th class="wc-shipping-zone-region"><?php esc_html_e( 'Region(s)', 'woocommerce' ); ?></th>
|
||||||
<th class="wc-shipping-zone-methods"><?php esc_html_e( 'Shipping Method(s)', 'woocommerce' ); ?></th>
|
<th class="wc-shipping-zone-methods"><?php esc_html_e( 'Shipping Method(s)', 'woocommerce' ); ?></th>
|
||||||
|
<th class="remove"> </th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4">
|
<td colspan="5">
|
||||||
<input type="submit" name="save" class="button button-primary wc-shipping-zone-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled />
|
<input type="submit" name="save" class="button button-primary wc-shipping-zone-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled />
|
||||||
<a class="button button-secondary wc-shipping-zone-add" href="#"><?php esc_html_e( 'Add shipping zone', 'woocommerce' ); ?></a>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
@ -32,14 +32,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
<td width="1%" class="wc-shipping-zone-worldwide"></td>
|
<td width="1%" class="wc-shipping-zone-worldwide"></td>
|
||||||
<td class="wc-shipping-zone-name">
|
<td class="wc-shipping-zone-name">
|
||||||
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=0' ) ); ?>"><?php esc_html_e( 'Rest of the World', 'woocommerce' ); ?></a>
|
<a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=0' ) ); ?>"><?php esc_html_e( 'Rest of the World', 'woocommerce' ); ?></a>
|
||||||
<div class="row-actions">
|
|
||||||
<a href="admin.php?page=wc-settings&tab=shipping&zone_id={{ data.zone_id }}"><?php _e( 'View', 'woocommerce' ); ?></a>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="wc-shipping-zone-region"><?php esc_html_e( 'This zone is used for shipping addresses that aren‘t included in any other shipping zone. Adding shipping methods to this zone is optional.', 'woocommerce' ); ?></td>
|
<td class="wc-shipping-zone-region"><?php _e( 'This zone is <b>optionally</b> used for regions that are not included in any other shipping zone.', 'woocommerce' ); ?></td>
|
||||||
<td class="wc-shipping-zone-methods">
|
<td class="wc-shipping-zone-methods">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="wc-shipping-zone-methods-add-row"><a href="#" class="add_shipping_method tips" data-tip="<?php esc_attr_e( 'Add shipping method', 'woocommerce' ); ?>" data-disabled-tip="<?php esc_attr_e( 'Save changes to continue adding shipping methods to this zone', 'woocommerce' ); ?>"><?php _e( 'Add shipping method', 'woocommerce' ); ?></a></li>
|
|
||||||
<?php
|
<?php
|
||||||
$worldwide = new WC_Shipping_Zone( 0 );
|
$worldwide = new WC_Shipping_Zone( 0 );
|
||||||
$methods = $worldwide->get_shipping_methods();
|
$methods = $worldwide->get_shipping_methods();
|
||||||
|
@ -56,6 +52,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="remove"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -63,7 +60,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
<script type="text/html" id="tmpl-wc-shipping-zone-row-blank">
|
<script type="text/html" id="tmpl-wc-shipping-zone-row-blank">
|
||||||
<?php if ( 0 === $method_count ) : ?>
|
<?php if ( 0 === $method_count ) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="wc-shipping-zones-blank-state" colspan="4">
|
<td class="wc-shipping-zones-blank-state" colspan="5">
|
||||||
<p class="main"><?php _e( 'A shipping zone is a geographic region where a certain set of shipping methods and rates apply.', 'woocommerce' ); ?></p>
|
<p class="main"><?php _e( 'A shipping zone is a geographic region where a certain set of shipping methods and rates apply.', 'woocommerce' ); ?></p>
|
||||||
<p><?php _e( 'For example:', 'woocommerce' ); ?></p>
|
<p><?php _e( 'For example:', 'woocommerce' ); ?></p>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -82,55 +79,15 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
<tr data-id="{{ data.zone_id }}">
|
<tr data-id="{{ data.zone_id }}">
|
||||||
<td width="1%" class="wc-shipping-zone-sort"></td>
|
<td width="1%" class="wc-shipping-zone-sort"></td>
|
||||||
<td class="wc-shipping-zone-name">
|
<td class="wc-shipping-zone-name">
|
||||||
<div class="view">
|
<a href="admin.php?page=wc-settings&tab=shipping&zone_id={{ data.zone_id }}">{{ data.zone_name }}</a>
|
||||||
<a href="admin.php?page=wc-settings&tab=shipping&zone_id={{ data.zone_id }}">{{ data.zone_name }}</a>
|
|
||||||
<div class="row-actions">
|
|
||||||
<a href="admin.php?page=wc-settings&tab=shipping&zone_id={{ data.zone_id }}"><?php _e( 'View', 'woocommerce' ); ?></a> | <a class="wc-shipping-zone-edit" href="#"><?php _e( 'Edit', 'woocommerce' ); ?></a> | <a href="#" class="wc-shipping-zone-delete"><?php _e( 'Remove', 'woocommerce' ); ?></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="edit">
|
|
||||||
<input type="text" name="zone_name[{{ data.zone_id }}]" data-attribute="zone_name" value="{{ data.zone_name }}" placeholder="<?php esc_attr_e( 'Zone Name', 'woocommerce' ); ?>" />
|
|
||||||
<div class="row-actions">
|
|
||||||
<a class="wc-shipping-zone-cancel-edit" href="#"><?php _e( 'Cancel changes', 'woocommerce' ); ?></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="wc-shipping-zone-region">
|
<td class="wc-shipping-zone-region">
|
||||||
<div class="view">{{ data.formatted_zone_location }}</div>
|
{{ data.formatted_zone_location }}
|
||||||
<div class="edit">
|
|
||||||
<select multiple="multiple" name="zone_locations[{{ data.zone_id }}]" data-attribute="zone_locations" data-placeholder="<?php _e( 'Select regions within this zone', 'woocommerce' ); ?>" class="wc-shipping-zone-region-select">
|
|
||||||
<?php
|
|
||||||
foreach ( $continents as $continent_code => $continent ) {
|
|
||||||
echo '<option value="continent:' . esc_attr( $continent_code ) . '" alt="">' . esc_html( $continent['name'] ) . '</option>';
|
|
||||||
|
|
||||||
$countries = array_intersect( array_keys( $allowed_countries ), $continent['countries'] );
|
|
||||||
|
|
||||||
foreach ( $countries as $country_code ) {
|
|
||||||
echo '<option value="country:' . esc_attr( $country_code ) . '" alt="' . esc_attr( $continent['name'] ) . '">' . esc_html( ' ' . $allowed_countries[ $country_code ] ) . '</option>';
|
|
||||||
|
|
||||||
if ( $states = WC()->countries->get_states( $country_code ) ) {
|
|
||||||
foreach ( $states as $state_code => $state_name ) {
|
|
||||||
echo '<option value="state:' . esc_attr( $country_code . ':' . $state_code ) . '" alt="' . esc_attr( $continent['name'] . ' ' . $allowed_countries[ $country_code ] ) . '">' . esc_html( ' ' . $state_name ) . '</option>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
<a class="wc-shipping-zone-postcodes-toggle" href="#"><?php _e( 'Limit to specific ZIP/postcodes', 'woocommerce' ); ?></a>
|
|
||||||
<div class="wc-shipping-zone-postcodes">
|
|
||||||
<textarea name="zone_postcodes[{{ data.zone_id }}]" data-attribute="zone_postcodes" placeholder="<?php esc_attr_e( 'List 1 postcode per line', 'woocommerce' ); ?>" class="input-text large-text" cols="25" rows="5"></textarea>
|
|
||||||
<span class="description"><?php _e( 'Postcodes containing wildcards (e.g. CB23*) and fully numeric ranges (e.g. <code>90210...99000</code>) are also supported.', 'woocommerce' ) ?></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
<td class="wc-shipping-zone-methods">
|
<td class="wc-shipping-zone-methods">
|
||||||
<div>
|
<div><ul></ul></div>
|
||||||
<ul>
|
|
||||||
<li class="wc-shipping-zone-methods-add-row"><a href="#" class="add_shipping_method tips" data-tip="<?php esc_attr_e( 'Add shipping method', 'woocommerce' ); ?>" data-disabled-tip="<?php esc_attr_e( 'Save changes to continue adding shipping methods to this zone', 'woocommerce' ); ?>"><?php _e( 'Add shipping method', 'woocommerce' ); ?></a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
|
<td class="remove"><a href="#" class="wc-shipping-zone-delete"><?php _e( 'Remove', 'woocommerce' ); ?></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -2875,51 +2875,16 @@ class WC_AJAX {
|
||||||
|
|
||||||
$zone_data = array_intersect_key( $data, array(
|
$zone_data = array_intersect_key( $data, array(
|
||||||
'zone_id' => 1,
|
'zone_id' => 1,
|
||||||
'zone_name' => 1,
|
'zone_order' => 1
|
||||||
'zone_order' => 1,
|
|
||||||
'zone_locations' => 1,
|
|
||||||
'zone_postcodes' => 1,
|
|
||||||
) );
|
) );
|
||||||
|
|
||||||
if ( isset( $zone_data['zone_id'] ) ) {
|
if ( isset( $zone_data['zone_id'] ) ) {
|
||||||
$zone = new WC_Shipping_Zone( $zone_data['zone_id'] );
|
$zone = new WC_Shipping_Zone( $zone_data['zone_id'] );
|
||||||
|
|
||||||
if ( isset( $zone_data['zone_name'] ) ) {
|
|
||||||
$zone->set_zone_name( $zone_data['zone_name'] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $zone_data['zone_order'] ) ) {
|
if ( isset( $zone_data['zone_order'] ) ) {
|
||||||
$zone->set_zone_order( $zone_data['zone_order'] );
|
$zone->set_zone_order( $zone_data['zone_order'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $zone_data['zone_locations'] ) ) {
|
|
||||||
$zone->clear_locations( array( 'state', 'country', 'continent' ) );
|
|
||||||
$locations = array_filter( array_map( 'wc_clean', (array) $zone_data['zone_locations'] ) );
|
|
||||||
foreach ( $locations as $location ) {
|
|
||||||
// Each posted location will be in the format type:code
|
|
||||||
$location_parts = explode( ':', $location );
|
|
||||||
switch ( $location_parts[0] ) {
|
|
||||||
case 'state' :
|
|
||||||
$zone->add_location( $location_parts[1] . ':' . $location_parts[2], 'state' );
|
|
||||||
break;
|
|
||||||
case 'country' :
|
|
||||||
$zone->add_location( $location_parts[1], 'country' );
|
|
||||||
break;
|
|
||||||
case 'continent' :
|
|
||||||
$zone->add_location( $location_parts[1], 'continent' );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $zone_data['zone_postcodes'] ) ) {
|
|
||||||
$zone->clear_locations( 'postcode' );
|
|
||||||
$postcodes = array_filter( array_map( 'strtoupper', array_map( 'wc_clean', explode( "\n", $zone_data['zone_postcodes'] ) ) ) );
|
|
||||||
foreach ( $postcodes as $postcode ) {
|
|
||||||
$zone->add_location( $postcode, 'postcode' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$zone->save();
|
$zone->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2949,13 +2914,13 @@ class WC_AJAX {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$zone_id = absint( $_POST['zone_id'] );
|
$zone_id = wc_clean( $_POST['zone_id'] );
|
||||||
$zone = WC_Shipping_Zones::get_zone( $zone_id );
|
$zone = new WC_Shipping_Zone( $zone_id );
|
||||||
$instance_id = $zone->add_shipping_method( wc_clean( $_POST['method_id'] ) );
|
$instance_id = $zone->add_shipping_method( wc_clean( $_POST['method_id'] ) );
|
||||||
|
|
||||||
wp_send_json_success( array(
|
wp_send_json_success( array(
|
||||||
'instance_id' => $instance_id,
|
'instance_id' => $instance_id,
|
||||||
'zone_id' => $zone_id,
|
'zone_id' => $zone->get_id(),
|
||||||
'methods' => $zone->get_shipping_methods(),
|
'methods' => $zone->get_shipping_methods(),
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
@ -2964,7 +2929,7 @@ class WC_AJAX {
|
||||||
* Handle submissions from assets/js/wc-shipping-zone-methods.js Backbone model.
|
* Handle submissions from assets/js/wc-shipping-zone-methods.js Backbone model.
|
||||||
*/
|
*/
|
||||||
public static function shipping_zone_methods_save_changes() {
|
public static function shipping_zone_methods_save_changes() {
|
||||||
if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['zone_id'], $_POST['changes'] ) ) {
|
if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['zone_id'] ) ) {
|
||||||
wp_send_json_error( 'missing_fields' );
|
wp_send_json_error( 'missing_fields' );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -2981,9 +2946,41 @@ class WC_AJAX {
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$zone_id = absint( $_POST['zone_id'] );
|
$zone_id = wc_clean( $_POST['zone_id'] );
|
||||||
$zone = new WC_Shipping_Zone( $zone_id );
|
$zone = new WC_Shipping_Zone( $zone_id );
|
||||||
$changes = $_POST['changes'];
|
$changes = isset( $_POST['changes'] ) ? $_POST['changes'] : array();
|
||||||
|
|
||||||
|
if ( isset( $_POST['zone_name'] ) ) {
|
||||||
|
$zone->set_zone_name( wc_clean( $_POST['zone_name'] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $_POST['zone_locations'] ) ) {
|
||||||
|
$zone->clear_locations( array( 'state', 'country', 'continent' ) );
|
||||||
|
$locations = array_filter( array_map( 'wc_clean', (array) $_POST['zone_locations'] ) );
|
||||||
|
foreach ( $locations as $location ) {
|
||||||
|
// Each posted location will be in the format type:code
|
||||||
|
$location_parts = explode( ':', $location );
|
||||||
|
switch ( $location_parts[0] ) {
|
||||||
|
case 'state' :
|
||||||
|
$zone->add_location( $location_parts[1] . ':' . $location_parts[2], 'state' );
|
||||||
|
break;
|
||||||
|
case 'country' :
|
||||||
|
$zone->add_location( $location_parts[1], 'country' );
|
||||||
|
break;
|
||||||
|
case 'continent' :
|
||||||
|
$zone->add_location( $location_parts[1], 'continent' );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $_POST['zone_postcodes'] ) ) {
|
||||||
|
$zone->clear_locations( 'postcode' );
|
||||||
|
$postcodes = array_filter( array_map( 'strtoupper', array_map( 'wc_clean', explode( "\n", $_POST['zone_postcodes'] ) ) ) );
|
||||||
|
foreach ( $postcodes as $postcode ) {
|
||||||
|
$zone->add_location( $postcode, 'postcode' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( $changes as $instance_id => $data ) {
|
foreach ( $changes as $instance_id => $data ) {
|
||||||
$method_id = $wpdb->get_var( $wpdb->prepare( "SELECT method_id FROM {$wpdb->prefix}woocommerce_shipping_zone_methods WHERE instance_id = %d", $instance_id ) );
|
$method_id = $wpdb->get_var( $wpdb->prepare( "SELECT method_id FROM {$wpdb->prefix}woocommerce_shipping_zone_methods WHERE instance_id = %d", $instance_id ) );
|
||||||
|
@ -3015,7 +3012,10 @@ class WC_AJAX {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$zone->save();
|
||||||
|
|
||||||
wp_send_json_success( array(
|
wp_send_json_success( array(
|
||||||
|
'zone_id' => $zone->get_id(),
|
||||||
'methods' => $zone->get_shipping_methods(),
|
'methods' => $zone->get_shipping_methods(),
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,7 +455,7 @@ class WC_Shipping_Zone extends WC_Data {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( null === $this->get_id() ) {
|
if ( null === $this->get_id() ) {
|
||||||
return 0;
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance_id = 0;
|
$instance_id = 0;
|
||||||
|
|
Loading…
Reference in New Issue