Fix save and striping

This commit is contained in:
Mike Jolley 2016-05-12 12:18:35 +01:00
parent 07db739a47
commit 986bd5abc7
9 changed files with 123 additions and 94 deletions

File diff suppressed because one or more lines are too long

View File

@ -2338,7 +2338,7 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
} }
} }
} }
tr.odd { tr.odd, .wc-shipping-class-rows tr:nth-child(odd) {
td { td {
background: #f9f9f9; background: #f9f9f9;
} }
@ -2395,7 +2395,7 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
input, select, textarea { input, select, textarea {
width: 100%; width: 100%;
} }
a.wc-shipping-zone-delete { a.wc-shipping-zone-delete, a.wc-shipping-class-delete {
color: red; color: red;
} }
.wc-shipping-zone-postcodes-toggle { .wc-shipping-zone-postcodes-toggle {

View File

@ -1,8 +1,7 @@
/* global shippingClassesLocalizeScript, ajaxurl */ /* global shippingClassesLocalizeScript, ajaxurl */
( function( $, data, wp, ajaxurl ) { ( function( $, data, wp, ajaxurl ) {
$( function() { $( function() {
var $table = $( '.wc-shipping-classes' ), var $tbody = $( '.wc-shipping-class-rows' ),
$tbody = $( '.wc-shipping-class-rows' ),
$save_button = $( '.wc-shipping-class-save' ), $save_button = $( '.wc-shipping-class-save' ),
$row_template = wp.template( 'wc-shipping-class-row' ), $row_template = wp.template( 'wc-shipping-class-row' ),
$blank_template = wp.template( 'wc-shipping-class-row-blank' ), $blank_template = wp.template( 'wc-shipping-class-row-blank' ),
@ -30,6 +29,17 @@
shippingClass.trigger( 'saved:classes' ); shippingClass.trigger( 'saved:classes' );
} }
}, },
discardChanges: function( id ) {
var changes = this.changes || {};
// Delete all changes
delete changes[ id ];
// No changes? Disable save button.
if ( 0 === _.size( this.changes ) ) {
shippingClassView.clearUnloadConfirmation();
}
},
onSaveResponse: function( response, textStatus ) { onSaveResponse: function( response, textStatus ) {
if ( 'success' === textStatus ) { if ( 'success' === textStatus ) {
if ( response.success ) { if ( response.success ) {
@ -38,12 +48,12 @@
shippingClass.changes = {}; shippingClass.changes = {};
shippingClass.trigger( 'saved:classes' ); shippingClass.trigger( 'saved:classes' );
} else if ( response.data ) { } else if ( response.data ) {
window.alert( response.data ); window.alert( response.data );
} else { } else {
window.alert( data.strings.save_failed ); window.alert( data.strings.save_failed );
} }
} }
shippingClassView.unblock(); shippingClassView.unblock();
} }
} ), } ),
@ -87,34 +97,36 @@
// Populate $tbody with the current classes // Populate $tbody with the current classes
$.each( classes, function( id, rowData ) { $.each( classes, function( id, rowData ) {
view.$el.append( view.rowTemplate( rowData ) ); view.renderRow( rowData );
var $tr = view.$el.find( 'tr[data-id="' + rowData.term_id + '"]');
// Editing?
if ( rowData.editing ) {
$tr.addClass( 'editing' );
}
} ); } );
// Make the rows function
this.$el.find('.view').show();
this.$el.find('.edit').hide();
this.$el.find( '.wc-shipping-class-edit' ).on( 'click', { view: this }, this.onEditRow );
this.$el.find( '.wc-shipping-class-delete' ).on( 'click', { view: this }, this.onDeleteRow );
this.$el.find( '.wc-shipping-class-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes );
this.$el.find('.editing .wc-shipping-class-edit').trigger('click');
// Stripe
if ( 0 === _.size( classes ) % 2) {
$table.find( 'tbody.wc-shipping-class-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' );
} else {
$table.find( 'tbody.wc-shipping-class-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
}
} else { } else {
view.$el.append( $blank_template ); view.$el.append( $blank_template );
} }
}, },
renderRow: function( rowData ) {
var view = this;
view.$el.append( view.rowTemplate( rowData ) );
view.initRow( rowData );
},
initRow: function( rowData ) {
var view = this;
var $tr = view.$el.find( 'tr[data-id="' + rowData.term_id + '"]');
// Make the rows function
$tr.find('.view').show();
$tr.find('.edit').hide();
$tr.find( '.wc-shipping-class-edit' ).on( 'click', { view: this }, this.onEditRow );
$tr.find( '.wc-shipping-class-delete' ).on( 'click', { view: this }, this.onDeleteRow );
$tr.find( '.wc-shipping-class-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes );
$tr.find( '.editing .wc-shipping-class-edit' ).trigger('click');
$tr.find( '.wc-shipping-class-cancel-edit' ).on( 'click', { view: this }, this.onCancelEditRow );
// Editing?
if ( true === rowData.editing ) {
$tr.addClass( 'editing' );
$tr.find( '.wc-shipping-class-edit' ).trigger( 'click' );
}
},
onSubmit: function( event ) { onSubmit: function( event ) {
event.data.view.block(); event.data.view.block();
event.data.view.model.save(); event.data.view.model.save();
@ -131,16 +143,13 @@
newRow = _.extend( {}, data.default_class, { newRow = _.extend( {}, data.default_class, {
term_id: 'new-' + size + '-' + Date.now(), term_id: 'new-' + size + '-' + Date.now(),
editing: true, editing: true,
newRow : true newRow : true
} ); } );
classes[ newRow.term_id ] = newRow;
changes[ newRow.term_id ] = newRow; changes[ newRow.term_id ] = newRow;
model.set( 'classes', classes );
model.logChanges( changes ); model.logChanges( changes );
view.renderRow( newRow );
view.render();
}, },
onEditRow: function( event ) { onEditRow: function( event ) {
event.preventDefault(); event.preventDefault();
@ -152,17 +161,39 @@
onDeleteRow: function( event ) { onDeleteRow: function( event ) {
var view = event.data.view, var view = event.data.view,
model = view.model, model = view.model,
classes = _.indexBy( model.get( 'classes' ), 'term_id' ), row = $( this ).closest('tr'),
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
changes = {}, changes = {},
term_id = $( this ).closest('tr').data('id'); term_id = $( this ).closest('tr').data('id');
event.preventDefault(); event.preventDefault();
delete classes[ term_id ]; if ( classes[ term_id ] ) {
changes[ term_id ] = _.extend( changes[ term_id ] || {}, { deleted : 'deleted' } ); delete classes[ term_id ];
model.set( 'classes', classes ); changes[ term_id ] = _.extend( changes[ term_id ] || {}, { deleted : 'deleted' } );
model.logChanges( changes ); model.set( 'classes', classes );
view.render(); model.logChanges( changes );
}
row.remove();
},
onCancelEditRow: function( event ) {
var view = event.data.view,
model = view.model,
row = $( this ).closest('tr'),
term_id = $( this ).closest('tr').data('id'),
classes = _.indexBy( model.get( 'classes' ), 'term_id' );
event.preventDefault();
model.discardChanges( term_id );
if ( classes[ term_id ] ) {
classes[ term_id ].editing = false;
row.after( view.rowTemplate( classes[ term_id ] ) );
view.initRow( classes[ term_id ] );
}
row.remove();
}, },
setUnloadConfirmation: function() { setUnloadConfirmation: function() {
this.needsUnloadConfirm = true; this.needsUnloadConfirm = true;
@ -188,10 +219,9 @@
classes = _.indexBy( model.get( 'classes' ), 'term_id' ), classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
changes = {}; changes = {};
if ( classes[ term_id ][ attribute ] !== value ) { if ( ! classes[ term_id ] || classes[ term_id ][ attribute ] !== value ) {
changes[ term_id ] = {}; changes[ term_id ] = {};
changes[ term_id ][ attribute ] = value; changes[ term_id ][ attribute ] = value;
classes[ term_id ][ attribute ] = value;
} }
model.logChanges( changes ); model.logChanges( changes );

View File

@ -1 +1 @@
!function(a,b,c,d){a(function(){var e=a(".wc-shipping-classes"),f=a(".wc-shipping-class-rows"),g=a(".wc-shipping-class-save"),h=c.template("wc-shipping-class-row"),i=c.template("wc-shipping-class-row-blank"),j=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{term_id:c},a)}),this.changes=b,this.trigger("change:classes")},save:function(){_.size(this.changes)?a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_classes_save_changes",{wc_shipping_classes_nonce:b.wc_shipping_classes_nonce,changes:this.changes},this.onSaveResponse,"json"):l.trigger("saved:classes")},onSaveResponse:function(a,c){"success"===c&&(a.success?(l.set("classes",a.data.shipping_classes),l.trigger("change:classes"),l.changes={},l.trigger("saved:classes")):a.data?window.alert(a.data):window.alert(b.strings.save_failed)),m.unblock()}}),k=Backbone.View.extend({rowTemplate:h,initialize:function(){this.listenTo(this.model,"change:classes",this.setUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.render),f.on("change",{view:this},this.updateModelOnChange),a(window).on("beforeunload",{view:this},this.unloadConfirmation),g.on("click",{view:this},this.onSubmit),a(document.body).on("click",".wc-shipping-class-add",{view:this},this.onAddNewRow),a(document.body).on("click",".wc-shipping-class-save-changes",{view:this},this.onSubmit)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var b=_.indexBy(this.model.get("classes"),"term_id"),c=this;this.$el.empty(),this.unblock(),_.size(b)?(b=_.sortBy(b,function(a){return a.name}),a.each(b,function(a,b){c.$el.append(c.rowTemplate(b));var d=c.$el.find('tr[data-id="'+b.term_id+'"]');b.editing&&d.addClass("editing")}),this.$el.find(".view").show(),this.$el.find(".edit").hide(),this.$el.find(".wc-shipping-class-edit").on("click",{view:this},this.onEditRow),this.$el.find(".wc-shipping-class-delete").on("click",{view:this},this.onDeleteRow),this.$el.find(".wc-shipping-class-postcodes-toggle").on("click",{view:this},this.onTogglePostcodes),this.$el.find(".editing .wc-shipping-class-edit").trigger("click"),0===_.size(b)%2?e.find("tbody.wc-shipping-class-rows").next("tbody").find("tr").addClass("odd"):e.find("tbody.wc-shipping-class-rows").next("tbody").find("tr").removeClass("odd")):c.$el.append(i)},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAddNewRow:function(a){a.preventDefault();var c=a.data.view,d=c.model,e=_.indexBy(d.get("classes"),"term_id"),f={},g=_.size(e),h=_.extend({},b.default_class,{term_id:"new-"+g+"-"+Date.now(),editing:!0,newRow:!0});e[h.term_id]=h,f[h.term_id]=h,d.set("classes",e),d.logChanges(f),c.render()},onEditRow:function(b){b.preventDefault(),a(this).closest("tr").addClass("editing"),a(this).closest("tr").find(".view").hide(),a(this).closest("tr").find(".edit").show(),b.data.view.model.trigger("change:classes")},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("classes"),"term_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f[g]=_.extend(f[g]||{},{deleted:"deleted"}),d.set("classes",e),d.logChanges(f),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("classes"),"term_id"),i={};h[e][f]!==g&&(i[e]={},i[e][f]=g,h[e][f]=g),c.logChanges(i)}}),l=new j({classes:b.classes}),m=new k({model:l,el:f});m.render()})}(jQuery,shippingClassesLocalizeScript,wp,ajaxurl); !function(a,b,c,d){a(function(){var e=a(".wc-shipping-class-rows"),f=a(".wc-shipping-class-save"),g=c.template("wc-shipping-class-row"),h=c.template("wc-shipping-class-row-blank"),i=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{term_id:c},a)}),this.changes=b,this.trigger("change:classes")},save:function(){_.size(this.changes)?a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_classes_save_changes",{wc_shipping_classes_nonce:b.wc_shipping_classes_nonce,changes:this.changes},this.onSaveResponse,"json"):k.trigger("saved:classes")},discardChanges:function(a){var b=this.changes||{};delete b[a],0===_.size(this.changes)&&l.clearUnloadConfirmation()},onSaveResponse:function(a,c){"success"===c&&(a.success?(k.set("classes",a.data.shipping_classes),k.trigger("change:classes"),k.changes={},k.trigger("saved:classes")):a.data?window.alert(a.data):window.alert(b.strings.save_failed)),l.unblock()}}),j=Backbone.View.extend({rowTemplate:g,initialize:function(){this.listenTo(this.model,"change:classes",this.setUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.render),e.on("change",{view:this},this.updateModelOnChange),a(window).on("beforeunload",{view:this},this.unloadConfirmation),f.on("click",{view:this},this.onSubmit),a(document.body).on("click",".wc-shipping-class-add",{view:this},this.onAddNewRow),a(document.body).on("click",".wc-shipping-class-save-changes",{view:this},this.onSubmit)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var b=_.indexBy(this.model.get("classes"),"term_id"),c=this;this.$el.empty(),this.unblock(),_.size(b)?(b=_.sortBy(b,function(a){return a.name}),a.each(b,function(a,b){c.renderRow(b)})):c.$el.append(h)},renderRow:function(a){var b=this;b.$el.append(b.rowTemplate(a)),b.initRow(a)},initRow:function(a){var b=this,c=b.$el.find('tr[data-id="'+a.term_id+'"]');c.find(".view").show(),c.find(".edit").hide(),c.find(".wc-shipping-class-edit").on("click",{view:this},this.onEditRow),c.find(".wc-shipping-class-delete").on("click",{view:this},this.onDeleteRow),c.find(".wc-shipping-class-postcodes-toggle").on("click",{view:this},this.onTogglePostcodes),c.find(".editing .wc-shipping-class-edit").trigger("click"),c.find(".wc-shipping-class-cancel-edit").on("click",{view:this},this.onCancelEditRow),!0===a.editing&&(c.addClass("editing"),c.find(".wc-shipping-class-edit").trigger("click"))},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAddNewRow:function(a){a.preventDefault();var c=a.data.view,d=c.model,e=_.indexBy(d.get("classes"),"term_id"),f={},g=_.size(e),h=_.extend({},b.default_class,{term_id:"new-"+g+"-"+Date.now(),editing:!0,newRow:!0});f[h.term_id]=h,d.logChanges(f),c.renderRow(h)},onEditRow:function(b){b.preventDefault(),a(this).closest("tr").addClass("editing"),a(this).closest("tr").find(".view").hide(),a(this).closest("tr").find(".edit").show(),b.data.view.model.trigger("change:classes")},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=a(this).closest("tr"),f=_.indexBy(d.get("classes"),"term_id"),g={},h=a(this).closest("tr").data("id");b.preventDefault(),f[h]&&(delete f[h],g[h]=_.extend(g[h]||{},{deleted:"deleted"}),d.set("classes",f),d.logChanges(g)),e.remove()},onCancelEditRow:function(b){var c=b.data.view,d=c.model,e=a(this).closest("tr"),f=a(this).closest("tr").data("id"),g=_.indexBy(d.get("classes"),"term_id");b.preventDefault(),d.discardChanges(f),g[f]&&(g[f].editing=!1,e.after(c.rowTemplate(g[f])),c.initRow(g[f])),e.remove()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,f.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,f.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("classes"),"term_id"),i={};h[e]&&h[e][f]===g||(i[e]={},i[e][f]=g),c.logChanges(i)}}),k=new i({classes:b.classes}),l=new j({model:k,el:e});l.render()})}(jQuery,shippingClassesLocalizeScript,wp,ajaxurl);

View File

@ -42,7 +42,7 @@
window.alert( data.strings.save_failed ); window.alert( data.strings.save_failed );
} }
} }
}, }
} ), } ),
// Backbone view // Backbone view

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,52 +8,57 @@ if ( ! defined( 'ABSPATH' ) ) {
<p><?php _e( 'Shipping classes can be used to group products of similar type. Assign classes to a product on the product edit screen. Once assigned, Shipping Classes can be used by some Shipping Methods (such as Flat Rate Shipping) to provide different rates to different classes of product.', 'woocommerce' ); ?><p> <p><?php _e( 'Shipping classes can be used to group products of similar type. Assign classes to a product on the product edit screen. Once assigned, Shipping Classes can be used by some Shipping Methods (such as Flat Rate Shipping) to provide different rates to different classes of product.', 'woocommerce' ); ?><p>
<table class="wc-shipping-classes widefat"> <table class="wc-shipping-classes widefat">
<thead> <thead>
<tr> <tr>
<th class="wc-shipping-class-name"><?php esc_html_e( 'Shipping Class', 'woocommerce' ); ?></th> <th class="wc-shipping-class-name"><?php esc_html_e( 'Shipping Class', 'woocommerce' ); ?></th>
<th class="wc-shipping-class-slug"><?php esc_html_e( 'Slug', 'woocommerce' ); ?></th> <th class="wc-shipping-class-slug"><?php esc_html_e( 'Slug', 'woocommerce' ); ?></th>
<th class="wc-shipping-class-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th> <th class="wc-shipping-class-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
<th class="wc-shipping-class-count"><?php esc_html_e( 'Product Count', 'woocommerce' ); ?></th> <th class="wc-shipping-class-count"><?php esc_html_e( 'Product Count', 'woocommerce' ); ?></th>
<th class="wc-shipping-class-actions">&nbsp;</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-class-save" value="<?php esc_attr_e( 'Save Shipping Classes', 'woocommerce' ); ?>" disabled />
<a class="button button-secondary wc-shipping-class-add" href="#"><?php esc_html_e( 'Add Shipping Class', 'woocommerce' ); ?></a> <a class="button button-secondary wc-shipping-class-add" href="#"><?php esc_html_e( 'Add Shipping Class', 'woocommerce' ); ?></a>
<input type="submit" name="save" class="button button-primary wc-shipping-class-save" value="<?php esc_attr_e( 'Save Shipping Classes', 'woocommerce' ); ?>" disabled /> </td>
</td> </tr>
</tr> </tfoot>
</tfoot> <tbody class="wc-shipping-class-rows"></tbody>
<tbody class="wc-shipping-class-rows"></tbody>
</table> </table>
<script type="text/html" id="tmpl-wc-shipping-class-row-blank"> <script type="text/html" id="tmpl-wc-shipping-class-row-blank">
<tr> <tr>
<td class="wc-shipping-classes-blank-state" colspan="4"><p><?php _e( 'No Shipping Classes have been created.', 'woocommerce' ); ?></p></td> <td class="wc-shipping-classes-blank-state" colspan="4"><p><?php _e( 'No Shipping classes have been created.', 'woocommerce' ); ?></p></td>
</tr> </tr>
</script> </script>
<script type="text/html" id="tmpl-wc-shipping-class-row"> <script type="text/html" id="tmpl-wc-shipping-class-row">
<tr data-id="{{ data.term_id }}"> <tr data-id="{{ data.term_id }}">
<td class="wc-shipping-class-name"> <td class="wc-shipping-class-name">
<div class="view">{{ data.name }}</div> <div class="view">
<div class="edit"><input type="text" name="name[{{ data.term_id }}]" data-attribute="name" value="{{ data.name }}" placeholder="<?php esc_attr_e( 'Shipping Class Name', 'woocommerce' ); ?>" /></div> {{ data.name }}
</td> <div class="row-actions">
<td class="wc-shipping-class-slug"> <a class="wc-shipping-class-edit" href="#"><?php _e( 'Edit', 'woocommerce' ); ?></a> | <a href="#" class="wc-shipping-class-delete"><?php _e( 'Remove', 'woocommerce' ); ?></a>
<div class="view">{{ data.slug }}</div> </div>
<div class="edit"><input type="text" name="slug[{{ data.term_id }}]" data-attribute="slug" value="{{ data.slug }}" placeholder="<?php esc_attr_e( 'Slug', 'woocommerce' ); ?>" /></div> </div>
</td> <div class="edit">
<td class="wc-shipping-class-description"> <input type="text" name="name[{{ data.term_id }}]" data-attribute="name" value="{{ data.name }}" placeholder="<?php esc_attr_e( 'Shipping Class Name', 'woocommerce' ); ?>" />
<div class="view">{{ data.description }}</div> <div class="row-actions">
<div class="edit"><input type="text" name="description[{{ data.term_id }}]" data-attribute="description" value="{{ data.description }}" placeholder="<?php esc_attr_e( 'Description for your reference', 'woocommerce' ); ?>" /></div> <a class="wc-shipping-class-cancel-edit" href="#"><?php _e( 'Cancel changes', 'woocommerce' ); ?></a>
</div>
</div>
</td> </td>
<td class="wc-shipping-class-count"> <td class="wc-shipping-class-slug">
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=product&product_shipping_class=' ) ); ?>{{data.slug}}">{{ data.count }}</a> <div class="view">{{ data.slug }}</div>
</td> <div class="edit"><input type="text" name="slug[{{ data.term_id }}]" data-attribute="slug" value="{{ data.slug }}" placeholder="<?php esc_attr_e( 'Slug', 'woocommerce' ); ?>" /></div>
<td class="wc-shipping-class-actions">
<a class="wc-shipping-class-delete tips" data-tip="<?php _e( 'Delete', 'woocommerce' ); ?>" href="#"><?php _e( 'Delete', 'woocommerce' ); ?></a>
<a class="wc-shipping-class-edit tips" data-tip="<?php _e( 'Edit', 'woocommerce' ); ?>" href="#"><?php _e( 'Edit', 'woocommerce' ); ?></a>
</td> </td>
</tr> <td class="wc-shipping-class-description">
<div class="view">{{ data.description }}</div>
<div class="edit"><input type="text" name="description[{{ data.term_id }}]" data-attribute="description" value="{{ data.description }}" placeholder="<?php esc_attr_e( 'Description for your reference', 'woocommerce' ); ?>" /></div>
</td>
<td class="wc-shipping-class-count">
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=product&product_shipping_class=' ) ); ?>{{data.slug}}">{{ data.count }}</a>
</td>
</tr>
</script> </script>

View File

@ -3321,18 +3321,12 @@ class WC_AJAX {
if ( isset( $data['newRow'] ) ) { if ( isset( $data['newRow'] ) ) {
$update_args = array_filter( $update_args ); $update_args = array_filter( $update_args );
if ( empty( $update_args['name'] ) ) { if ( empty( $update_args['name'] ) ) {
wp_send_json_error( __( 'Shipping Class name is required', 'woocommerce' ) ); continue;
exit;
} }
$result = wp_insert_term( $update_args['name'], 'product_shipping_class', $update_args ); $result = wp_insert_term( $update_args['name'], 'product_shipping_class', $update_args );
} else { } else {
$result = wp_update_term( $term_id, 'product_shipping_class', $update_args ); $result = wp_update_term( $term_id, 'product_shipping_class', $update_args );
} }
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result->get_error_message() );
exit;
}
} }
$wc_shipping = WC_Shipping::instance(); $wc_shipping = WC_Shipping::instance();