Merge remote-tracking branch 'woothemes/master'

This commit is contained in:
Job 2016-05-16 15:50:31 +02:00
commit a4f0fd2bd8
205 changed files with 8987 additions and 4714 deletions

View File

@ -4,8 +4,7 @@ filter:
- apigen/*
- dummy-data/*
- i18n/*
- includes/api/v1/*
- includes/api/v2/*
- includes/api/legacy/*
- includes/libraries/*
- includes/updates/*
- includes/gateways/simplify-commerce/includes/*

View File

@ -29,7 +29,7 @@ main: WC
title: WooCommerce 2.5.x Code Reference
# base url used for sitemap (useful for public doc)
baseUrl: http://docs.woothemes.com/wc-apidocs/
baseUrl: https://docs.woothemes.com/wc-apidocs/
# choose ApiGen template theme
templateTheme: default

View File

@ -190,7 +190,7 @@
content: $glyph;
}
@mixin icon_dashicons( $glyph: "\e001" ) {
@mixin icon_dashicons( $glyph: "\f333" ) {
font-family: 'Dashicons';
speak: none;
font-weight: normal;

File diff suppressed because one or more lines are too long

View File

@ -229,6 +229,11 @@ mark.amount {
}
}
h2 .woocommerce-help-tip {
margin-top: -5px;
margin-left: .25em;
}
table.wc_status_table {
margin-bottom: 1em;
@ -1313,24 +1318,20 @@ ul.wc_coupon_list_block {
td.line_tax {
.delete-order-tax {
@include ir();
font-size: 12px;
visibility: hidden;
float: right;
margin: 2px -16px 0 0;
font-size: 14px;
visibility: hidden;
margin: 3px -18px 0 0;
&:before {
@include icon( "\e013" );
color: white;
background-color: #000;
-webkit-border-radius: 100%;
border-radius: 100%;
border: 1px solid #000;
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
@include icon_dashicons( "\f153" );
color: #999;
}
&:hover:before {
border-color: $red;
background-color: $red;
&:hover {
&:before {
color: $red;
}
}
}
@ -2342,7 +2343,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 {
background: #f9f9f9;
}
@ -2387,21 +2388,6 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
line-height: 24px;
}
}
.wc-shipping-zone-method-enabled {
text-align: center;
.status-enabled {
display: inline-block;
&:before {
line-height: inherit;
}
}
.status-disabled {
display: inline-block;
&:before {
line-height: inherit;
}
}
}
.wc-shipping-zone-name,
.wc-shipping-zone-methods {
width: 25%;
@ -2414,6 +2400,9 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
input, select, textarea {
width: 100%;
}
a.wc-shipping-zone-delete, a.wc-shipping-class-delete {
color: red;
}
.wc-shipping-zone-postcodes-toggle {
float: right;
margin: 0;
@ -2441,6 +2430,8 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
}
ul {
color: #999;
position: relative;
padding-right: 32px;
li {
display: inline;
margin: 0 0 0 0;
@ -2458,60 +2449,58 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
margin: 0 !important;
}
li.wc-shipping-zone-methods-add-row {
margin: .5em 0 0;
position: absolute;
right: 0;
top: 0;
}
}
.button {
display: inline-block;
}
}
.wc-shipping-zone-actions, .wc-shipping-zone-method-actions, .wc-shipping-class-actions {
width: 4em;
a {
@include ir();
float: right;
padding: .5em;
.add_shipping_method {
display: block;
width: 24px;
padding: 24px 0 0 0;
height: 0;
overflow: hidden;
cursor: pointer;
line-height: 24px;
&:before {
@include icon;
font-family: 'Dashicons';
content: "\f502";
color: #999;
vertical-align: middle;
line-height: 24px;
font-size: 16px;
margin: 0;
}
&:hover {
&.disabled {
cursor: not-allowed;
&:before {
color: #0073aa;
color: #ccc;
}
}
}
a.wc-shipping-zone-delete, a.wc-shipping-zone-method-delete, a.wc-shipping-class-delete {
}
.wc-shipping-zone-method-title {
width: 33%;
.wc-shipping-zone-method-delete {
color: red;
}
}
.wc-shipping-zone-method-enabled {
text-align: center;
.status-enabled {
margin-top: 1px;
display: inline-block;
&:before {
content: "\f158";
}
&:hover {
&:before {
color: $red;
}
line-height: inherit;
}
}
a.wc-shipping-class-edit {
.status-disabled {
margin-top: 1px;
display: inline-block;
&:before {
content: "\f464";
}
}
a.wc-shipping-zone-method-settings {
&:before {
content: "\f111";
margin-top: -1px;
line-height: inherit;
}
}
}
@ -2519,17 +2508,10 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
input, select {
vertical-align: middle !important;
}
.button-primary {
.button-secondary {
float: right;
}
}
.wc-shipping-zone-method-selector {
float: left;
select {
margin:0;
height: 29px;
}
}
.editing {
.wc-shipping-zone-view, .wc-shipping-zone-edit {
display: none;
@ -2915,15 +2897,14 @@ img.help_tip {
font-size: 1.4em;
&:before {
@include icon( "\e013" );
color: white;
background-color: #000;
@include border-radius(100%);
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
@include icon_dashicons( "\f153" );
color: #999;
}
&:hover before {
background-color: $red;
&:hover {
&:before {
color: $red;
}
}
}
}
@ -3261,6 +3242,11 @@ img.help_tip {
th {
padding: 7px 0 7px 7px !important;
.woocommerce-help-tip {
font-size: 1.1em;
margin-left: 0;
}
}
td {
@ -3287,10 +3273,10 @@ img.help_tip {
.delete {
@include ir();
font-size: 1.2em;
&:before {
@include icon;
content: "\e013";
@include icon_dashicons( "\f153" );
color: #999;
}
@ -3302,17 +3288,14 @@ img.help_tip {
}
}
th.sort {
width: 17px;
padding: 0;
}
td.sort {
padding: 0 8px;
cursor: move;
width: 17px;
background: #f9f9f9;
text-align: center;
vertical-align: middle;
padding-right: 7px !important;
&:before {
content: "\f333";
@ -4653,9 +4636,10 @@ table.bar_chart {
}
.short,
input[type=email].short,
input[type=number].short,
input[type=text].short,
input[type="text"].short,
input[type="email"].short,
input[type="number"].short,
input[type="password"].short,
.dimensions_field .wrap {
width: 80%;
}
@ -4883,6 +4867,9 @@ table.bar_chart {
top: 50%;
transform: translate(-50%, -50%);
width: 500px;
article {
overflow: auto;
}
}
&.wc-backbone-modal-shipping-method-settings {
@ -5006,6 +4993,7 @@ table.bar_chart {
font-size: inherit;
font-weight: inherit;
padding: 3px 5px;
width: 100% !important;
}
.select2-container {
line-height: 1.85em;

View File

@ -1 +1 @@
@charset "UTF-8";@font-face{font-family:star;src:url(../fonts/star.eot);src:url(../fonts/star.eot?#iefix) format("embedded-opentype"),url(../fonts/star.woff) format("woff"),url(../fonts/star.ttf) format("truetype"),url(../fonts/star.svg#star) format("svg");font-weight:400;font-style:normal}@font-face{font-family:WooCommerce;src:url(../fonts/WooCommerce.eot);src:url(../fonts/WooCommerce.eot?#iefix) format("embedded-opentype"),url(../fonts/WooCommerce.woff) format("woff"),url(../fonts/WooCommerce.ttf) format("truetype"),url(../fonts/WooCommerce.svg#WooCommerce) format("svg");font-weight:400;font-style:normal}#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image:before{font-family:WooCommerce!important;content:"\e03d";font-size:1.3em!important}#adminmenu #menu-posts-product .menu-icon-post div.wp-menu-image:before,#adminmenu #menu-posts-product .menu-icon-product div.wp-menu-image:before{font-family:WooCommerce!important;content:"\e006";font-size:1.3em!important}#adminmenu #toplevel_page_wc-reports .menu-icon-generic div.wp-menu-image:before{font-family:WooCommerce!important;content:"\e023";font-size:1.3em!important}span.mce_woocommerce_shortcodes_button{background-image:none!important;display:block;text-indent:-9999px;position:relative;height:1em;width:1em}span.mce_woocommerce_shortcodes_button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;margin:0;text-indent:0;position:absolute;top:0;left:0;width:100%;height:100%;text-align:center;content:"";font-size:.9em;line-height:1.2}.wc_plugin_upgrade_notice{font-weight:400;color:#fff;background:#d54d21;padding:1em;margin:9px 0}.wc_plugin_upgrade_notice a{color:#fff;text-decoration:underline}.wc_plugin_upgrade_notice:before{content:"\f348";display:inline-block;font:400 18px/1 dashicons;speak:none;margin:0 8px 0 -2px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;vertical-align:top}
@charset "UTF-8";@font-face{font-family:star;src:url(../fonts/star.eot);src:url(../fonts/star.eot?#iefix) format("embedded-opentype"),url(../fonts/star.woff) format("woff"),url(../fonts/star.ttf) format("truetype"),url(../fonts/star.svg#star) format("svg");font-weight:400;font-style:normal}@font-face{font-family:WooCommerce;src:url(../fonts/WooCommerce.eot);src:url(../fonts/WooCommerce.eot?#iefix) format("embedded-opentype"),url(../fonts/WooCommerce.woff) format("woff"),url(../fonts/WooCommerce.ttf) format("truetype"),url(../fonts/WooCommerce.svg#WooCommerce) format("svg");font-weight:400;font-style:normal}#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image:before{font-family:WooCommerce!important;content:"\e03d"}#adminmenu #menu-posts-product .menu-icon-post div.wp-menu-image:before,#adminmenu #menu-posts-product .menu-icon-product div.wp-menu-image:before{font-family:WooCommerce!important;content:"\e006"}#adminmenu #toplevel_page_wc-reports .menu-icon-generic div.wp-menu-image:before{font-family:WooCommerce!important;content:"\e023";font-size:1.3em!important}span.mce_woocommerce_shortcodes_button{background-image:none!important;display:block;text-indent:-9999px;position:relative;height:1em;width:1em}span.mce_woocommerce_shortcodes_button:before{font-family:WooCommerce;speak:none;font-weight:400;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;margin:0;text-indent:0;position:absolute;top:0;left:0;width:100%;height:100%;text-align:center;content:"";font-size:.9em;line-height:1.2}.wc_plugin_upgrade_notice{font-weight:400;color:#fff;background:#d54d21;padding:1em;margin:9px 0}.wc_plugin_upgrade_notice a{color:#fff;text-decoration:underline}.wc_plugin_upgrade_notice:before{content:"\f348";display:inline-block;font:400 18px/1 dashicons;speak:none;margin:0 8px 0 -2px;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;vertical-align:top}

View File

@ -18,14 +18,12 @@
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image:before {
font-family: 'WooCommerce' !important;
content: "\e03d";
font-size: 1.3em !important;
}
#adminmenu #menu-posts-product .menu-icon-post div.wp-menu-image:before,
#adminmenu #menu-posts-product .menu-icon-product div.wp-menu-image:before {
font-family: 'WooCommerce' !important;
content: "\e006";
font-size: 1.3em !important;
}
#adminmenu #toplevel_page_wc-reports .menu-icon-generic div.wp-menu-image:before {

File diff suppressed because one or more lines are too long

View File

@ -612,7 +612,6 @@ p.demo_store {
line-height: 1;
cursor: pointer;
position: relative;
font-family: inherit;
text-decoration: none;
overflow: visible;
padding: .618em 1em;
@ -691,6 +690,7 @@ p.demo_store {
color: inherit;
cursor: not-allowed;
opacity: 0.5;
padding: .618em 1em;
&:hover {
color: inherit;
@ -1854,6 +1854,15 @@ p.demo_store {
color: darken( $secondary, 20% );
}
.wc-saved-payment-methods {
list-style: none outside;
margin: 0;
}
.wc-credit-card-form {
border: 0;
padding: 0;
margin: 1em 0 0;
}
.wc-credit-card-form-card-number,
.wc-credit-card-form-card-expiry,
.wc-credit-card-form-card-cvc {

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -53,15 +53,28 @@
_string: undefined,
events: {
'click .modal-close': 'closeButton',
'click #btn-ok': 'addButton',
'click #btn-ok' : 'addButton',
'touchstart #btn-ok': 'addButton',
'keydown': 'keyboardActions'
'keydown' : 'keyboardActions'
},
resizeContent: function() {
var $content = $( '.wc-backbone-modal-content' ).find( 'article' );
var max_h = $( window ).height() * 0.75;
$content.css({
'max-height': max_h + 'px'
});
},
initialize: function( data ) {
var view = this;
this._target = data.target;
this._string = data.string;
_.bindAll( this, 'render' );
this.render();
$( window ).resize(function() {
view.resizeContent();
});
},
render: function() {
var template = wp.template( this._target );
@ -74,26 +87,7 @@
'overflow': 'hidden'
}).append( this.$el );
var $content = $( '.wc-backbone-modal-content' ).find( 'article' );
var content_h = ( $content.height() < 90 ) ? 90 : $content.height();
var max_h = $( window ).height() * 0.75;
if ( content_h > max_h ) {
$content.css({
'overflow': 'auto',
height: max_h + 'px'
});
} else {
$content.css({
'overflow': 'visible',
height: ( content_h > 90 ) ? 'auto' : content_h + 'px'
});
}
/*$( '.wc-backbone-modal-content' ).css({
'margin-top': '-' + ( $( '.wc-backbone-modal-content' ).height() / 2 ) + 'px',
'margin-left': '-' + ( $( '.wc-backbone-modal-content' ).width() / 2 ) + 'px'
});*/
this.resizeContent();
$( document.body ).trigger( 'wc_backbone_modal_loaded', this._target );
},

View File

@ -1 +1 @@
!function(a,b,c){"use strict";a.fn.WCBackboneModal=function(b){return this.each(function(){new a.WCBackboneModal(a(this),b)})},a.WCBackboneModal=function(b,c){var d=a.extend({},a.WCBackboneModal.defaultOptions,c);d.template&&new a.WCBackboneModal.View({target:d.template,string:d.variable})},a.WCBackboneModal.defaultOptions={template:"",variable:{}},a.WCBackboneModal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,_string:void 0,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions"},initialize:function(a){this._target=a.target,this._string=a.string,c.bindAll(this,"render"),this.render()},render:function(){var b=wp.template(this._target);this.$el.attr("tabindex","0").append(b(this._string)),a(document.body).css({overflow:"hidden"}).append(this.$el);var c=a(".wc-backbone-modal-content").find("article"),d=c.height()<90?90:c.height(),e=.75*a(window).height();d>e?c.css({overflow:"auto",height:e+"px"}):c.css({overflow:"visible",height:d>90?"auto":d+"px"}),a(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),a(document.body).trigger("wc_backbone_modal_before_remove",this._target),this.undelegateEvents(),a(document).off("focusin"),a(document.body).css({overflow:"auto"}),this.remove(),a(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(b){a(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(b)},getFormData:function(){var b={};return a(document.body).trigger("wc_backbone_modal_before_update",this._target),a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b},keyboardActions:function(a){var b=a.keyCode||a.which;13!==b||a.target.tagName&&("input"===a.target.tagName.toLowerCase()||"textarea"===a.target.tagName.toLowerCase())||this.addButton(a),27===b&&this.closeButton(a)}})}(jQuery,Backbone,_);
!function(a,b,c){"use strict";a.fn.WCBackboneModal=function(b){return this.each(function(){new a.WCBackboneModal(a(this),b)})},a.WCBackboneModal=function(b,c){var d=a.extend({},a.WCBackboneModal.defaultOptions,c);d.template&&new a.WCBackboneModal.View({target:d.template,string:d.variable})},a.WCBackboneModal.defaultOptions={template:"",variable:{}},a.WCBackboneModal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,_string:void 0,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions"},resizeContent:function(){var b=a(".wc-backbone-modal-content").find("article"),c=.75*a(window).height();b.css({"max-height":c+"px"})},initialize:function(b){var d=this;this._target=b.target,this._string=b.string,c.bindAll(this,"render"),this.render(),a(window).resize(function(){d.resizeContent()})},render:function(){var b=wp.template(this._target);this.$el.attr("tabindex","0").append(b(this._string)),a(document.body).css({overflow:"hidden"}).append(this.$el),this.resizeContent(),a(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),a(document.body).trigger("wc_backbone_modal_before_remove",this._target),this.undelegateEvents(),a(document).off("focusin"),a(document.body).css({overflow:"auto"}),this.remove(),a(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(b){a(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(b)},getFormData:function(){var b={};return a(document.body).trigger("wc_backbone_modal_before_update",this._target),a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b},keyboardActions:function(a){var b=a.keyCode||a.which;13!==b||a.target.tagName&&("input"===a.target.tagName.toLowerCase()||"textarea"===a.target.tagName.toLowerCase())||this.addButton(a),27===b&&this.closeButton(a)}})}(jQuery,Backbone,_);

View File

@ -848,7 +848,7 @@ jQuery( function ( $ ) {
data: data,
type: 'POST',
success: function() {
$row.hide();
$row.remove();
wc_meta_boxes_order_items.unblock();
}
});
@ -1189,25 +1189,27 @@ jQuery( function ( $ ) {
},
delete_order_note: function() {
var note = $( this ).closest( 'li.note' );
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_delete_note ) ) {
var note = $( this ).closest( 'li.note' );
$( note ).block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
$( note ).block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
var data = {
action: 'woocommerce_delete_order_note',
note_id: $( note ).attr( 'rel' ),
security: woocommerce_admin_meta_boxes.delete_order_note_nonce
};
var data = {
action: 'woocommerce_delete_order_note',
note_id: $( note ).attr( 'rel' ),
security: woocommerce_admin_meta_boxes.delete_order_note_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function() {
$( note ).remove();
});
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function() {
$( note ).remove();
});
}
return false;
}

File diff suppressed because one or more lines are too long

View File

@ -1,150 +0,0 @@
/*global jQuery, Backbone, _ */
( function( $, Backbone, _ ) {
'use strict';
/**
* WooCommerce Backbone Modal plugin
*
* @param {object} options
*/
$.fn.WCBackboneModal = function( options ) {
return this.each( function() {
( new $.WCBackboneModal( $( this ), options ) );
});
};
/**
* Initialize the Backbone Modal
*
* @param {object} element [description]
* @param {object} options [description]
*/
$.WCBackboneModal = function( element, options ) {
// Set settings
var settings = $.extend( {}, $.WCBackboneModal.defaultOptions, options );
if ( settings.template ) {
new $.WCBackboneModal.View({
target: settings.template,
string: settings.variable
});
}
};
/**
* Set default options
*
* @type {object}
*/
$.WCBackboneModal.defaultOptions = {
template: '',
variable: {}
};
/**
* Create the Backbone Modal
*
* @return {null}
*/
$.WCBackboneModal.View = Backbone.View.extend({
tagName: 'div',
id: 'wc-backbone-modal-dialog',
_target: undefined,
_string: undefined,
events: {
'click .modal-close': 'closeButton',
'click #btn-ok': 'addButton',
'touchstart #btn-ok': 'addButton',
'keydown': 'keyboardActions'
},
initialize: function( data ) {
this._target = data.target;
this._string = data.string;
_.bindAll( this, 'render' );
this.render();
},
render: function() {
var template = wp.template( this._target );
this.$el.attr( 'tabindex' , '0' ).append(
template( this._string )
);
$( document.body ).css({
'overflow': 'hidden'
}).append( this.$el );
var $content = $( '.wc-backbone-modal-content' ).find( 'article' );
var content_h = ( $content.height() < 90 ) ? 90 : $content.height();
var max_h = $( window ).height() - 200;
if ( max_h > 400 ) {
max_h = 400;
}
if ( content_h > max_h ) {
$content.css({
'overflow': 'auto',
height: max_h + 'px'
});
} else {
$content.css({
'overflow': 'visible',
height: ( content_h > 90 ) ? 'auto' : content_h + 'px'
});
}
$( '.wc-backbone-modal-content' ).css({
'margin-top': '-' + ( $( '.wc-backbone-modal-content' ).height() / 2 ) + 'px',
'margin-left': '-' + ( $( '.wc-backbone-modal-content' ).width() / 2 ) + 'px'
});
$( document.body ).trigger( 'wc_backbone_modal_loaded', this._target );
},
closeButton: function( e ) {
e.preventDefault();
$( document.body ).trigger( 'wc_backbone_modal_before_remove', this._target );
this.undelegateEvents();
$( document ).off( 'focusin' );
$( document.body ).css({
'overflow': 'auto'
});
this.remove();
$( document.body ).trigger( 'wc_backbone_modal_removed', this._target );
},
addButton: function( e ) {
$( document.body ).trigger( 'wc_backbone_modal_response', [ this._target, this.getFormData() ] );
this.closeButton( e );
},
getFormData: function() {
var data = {};
$( document.body ).trigger( 'wc_backbone_modal_before_update', this._target );
$.each( $( 'form', this.$el ).serializeArray(), function( index, item ) {
if ( data.hasOwnProperty( item.name ) ) {
data[ item.name ] = $.makeArray( data[ item.name ] );
data[ item.name ].push( item.value );
} else {
data[ item.name ] = item.value;
}
});
return data;
},
keyboardActions: function( e ) {
var button = e.keyCode || e.which;
// Enter key
if ( 13 === button && ! ( e.target.tagName && ( e.target.tagName.toLowerCase() === 'input' || e.target.tagName.toLowerCase() === 'textarea' ) ) ) {
this.addButton( e );
}
// ESC key
if ( 27 === button ) {
this.closeButton( e );
}
}
});
}( jQuery, Backbone, _ ));

View File

@ -1 +0,0 @@
!function(a,b,c){"use strict";a.fn.WCBackboneModal=function(b){return this.each(function(){new a.WCBackboneModal(a(this),b)})},a.WCBackboneModal=function(b,c){var d=a.extend({},a.WCBackboneModal.defaultOptions,c);d.template&&new a.WCBackboneModal.View({target:d.template,string:d.variable})},a.WCBackboneModal.defaultOptions={template:"",variable:{}},a.WCBackboneModal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,_string:void 0,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions"},initialize:function(a){this._target=a.target,this._string=a.string,c.bindAll(this,"render"),this.render()},render:function(){var b=wp.template(this._target);this.$el.attr("tabindex","0").append(b(this._string)),a(document.body).css({overflow:"hidden"}).append(this.$el);var c=a(".wc-backbone-modal-content").find("article"),d=c.height()<90?90:c.height(),e=a(window).height()-200;e>400&&(e=400),d>e?c.css({overflow:"auto",height:e+"px"}):c.css({overflow:"visible",height:d>90?"auto":d+"px"}),a(".wc-backbone-modal-content").css({"margin-top":"-"+a(".wc-backbone-modal-content").height()/2+"px","margin-left":"-"+a(".wc-backbone-modal-content").width()/2+"px"}),a(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),a(document.body).trigger("wc_backbone_modal_before_remove",this._target),this.undelegateEvents(),a(document).off("focusin"),a(document.body).css({overflow:"auto"}),this.remove(),a(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(b){a(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(b)},getFormData:function(){var b={};return a(document.body).trigger("wc_backbone_modal_before_update",this._target),a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b},keyboardActions:function(a){var b=a.keyCode||a.which;13!==b||a.target.tagName&&("input"===a.target.tagName.toLowerCase()||"textarea"===a.target.tagName.toLowerCase())||this.addButton(a),27===b&&this.closeButton(a)}})}(jQuery,Backbone,_);

View File

@ -1,4 +1,4 @@
/*global ajaxurl, inlineEditPost, inlineEditL10n */
/*global ajaxurl, inlineEditPost, inlineEditL10n, woocommerce_admin */
jQuery(function( $ ) {
$( '#the-list' ).on( 'click', '.editinline', function() {
@ -28,9 +28,12 @@ jQuery(function( $ ) {
tax_class = $wc_inline_data.find( '.tax_class' ).text(),
backorders = $wc_inline_data.find( '.backorders' ).text();
var formatted_regular_price = regular_price.replace('.', woocommerce_admin.mon_decimal_point ),
formatted_sale_price = sale_price.replace('.', woocommerce_admin.mon_decimal_point );
$( 'input[name="_sku"]', '.inline-edit-row' ).val( sku );
$( 'input[name="_regular_price"]', '.inline-edit-row' ).val( regular_price );
$( 'input[name="_sale_price"]', '.inline-edit-row' ).val( sale_price );
$( 'input[name="_regular_price"]', '.inline-edit-row' ).val( formatted_regular_price );
$( 'input[name="_sale_price"]', '.inline-edit-row' ).val( formatted_sale_price );
$( 'input[name="_weight"]', '.inline-edit-row' ).val( weight );
$( 'input[name="_length"]', '.inline-edit-row' ).val( length );
$( 'input[name="_width"]', '.inline-edit-row' ).val( width );

View File

@ -1 +1 @@
jQuery(function(a){a("#the-list").on("click",".editinline",function(){inlineEditPost.revert();var b=a(this).closest("tr").attr("id");b=b.replace("post-","");var c=a("#woocommerce_inline_"+b),d=c.find(".sku").text(),e=c.find(".regular_price").text(),f=c.find(".sale_price ").text(),g=c.find(".weight").text(),h=c.find(".length").text(),i=c.find(".width").text(),j=c.find(".height").text(),k=c.find(".shipping_class").text(),l=c.find(".visibility").text(),m=c.find(".stock_status").text(),n=c.find(".stock").text(),o=c.find(".featured").text(),p=c.find(".manage_stock").text(),q=c.find(".menu_order").text(),r=c.find(".tax_status").text(),s=c.find(".tax_class").text(),t=c.find(".backorders").text();a('input[name="_sku"]',".inline-edit-row").val(d),a('input[name="_regular_price"]',".inline-edit-row").val(e),a('input[name="_sale_price"]',".inline-edit-row").val(f),a('input[name="_weight"]',".inline-edit-row").val(g),a('input[name="_length"]',".inline-edit-row").val(h),a('input[name="_width"]',".inline-edit-row").val(i),a('input[name="_height"]',".inline-edit-row").val(j),a('select[name="_shipping_class"] option:selected',".inline-edit-row").attr("selected",!1).change(),a('select[name="_shipping_class"] option[value="'+k+'"]').attr("selected","selected").change(),a('input[name="_stock"]',".inline-edit-row").val(n),a('input[name="menu_order"]',".inline-edit-row").val(q),a('select[name="_tax_status"] option, select[name="_tax_class"] option, select[name="_visibility"] option, select[name="_stock_status"] option, select[name="_backorders"] option').removeAttr("selected"),a('select[name="_tax_status"] option[value="'+r+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_tax_class"] option[value="'+s+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_visibility"] option[value="'+l+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_stock_status"] option[value="'+m+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_backorders"] option[value="'+t+'"]',".inline-edit-row").attr("selected","selected"),"yes"===o?a('input[name="_featured"]',".inline-edit-row").attr("checked","checked"):a('input[name="_featured"]',".inline-edit-row").removeAttr("checked"),"yes"===p?(a(".stock_qty_field",".inline-edit-row").show().removeAttr("style"),a('input[name="_manage_stock"]',".inline-edit-row").attr("checked","checked")):(a(".stock_qty_field",".inline-edit-row").hide(),a('input[name="_manage_stock"]',".inline-edit-row").removeAttr("checked"));var u=c.find(".product_type").text(),v=c.find(".product_is_virtual").text();"simple"===u||"external"===u?a(".price_fields",".inline-edit-row").show().removeAttr("style"):a(".price_fields",".inline-edit-row").hide(),"yes"===v?a(".dimension_fields",".inline-edit-row").hide():a(".dimension_fields",".inline-edit-row").show().removeAttr("style"),"grouped"===u?a(".stock_fields",".inline-edit-row").hide():a(".stock_fields",".inline-edit-row").show().removeAttr("style")}),a("#the-list").on("change",'.inline-edit-row input[name="_manage_stock"]',function(){a(this).is(":checked")?a(".stock_qty_field",".inline-edit-row").show().removeAttr("style"):a(".stock_qty_field",".inline-edit-row").hide()}),a("#wpbody").on("click","#doaction, #doaction2",function(){a("input.text",".inline-edit-row").val(""),a("#woocommerce-fields").find("select").prop("selectedIndex",0),a("#woocommerce-fields-bulk").find(".inline-edit-group .change-input").hide();var b="product_tag";a('tr.inline-editor textarea[name="tax_input['+b+']"]').suggest(ajaxurl+(ajaxurl.indexOf("?")>0?"&":"?")+"action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:inlineEditL10n.comma})}),a("#wpbody").on("change","#woocommerce-fields-bulk .inline-edit-group .change_to",function(){0<a(this).val()?a(this).closest("div").find(".change-input").show():a(this).closest("div").find(".change-input").hide()})});
jQuery(function(a){a("#the-list").on("click",".editinline",function(){inlineEditPost.revert();var b=a(this).closest("tr").attr("id");b=b.replace("post-","");var c=a("#woocommerce_inline_"+b),d=c.find(".sku").text(),e=c.find(".regular_price").text(),f=c.find(".sale_price ").text(),g=c.find(".weight").text(),h=c.find(".length").text(),i=c.find(".width").text(),j=c.find(".height").text(),k=c.find(".shipping_class").text(),l=c.find(".visibility").text(),m=c.find(".stock_status").text(),n=c.find(".stock").text(),o=c.find(".featured").text(),p=c.find(".manage_stock").text(),q=c.find(".menu_order").text(),r=c.find(".tax_status").text(),s=c.find(".tax_class").text(),t=c.find(".backorders").text(),u=e.replace(".",woocommerce_admin.mon_decimal_point),v=f.replace(".",woocommerce_admin.mon_decimal_point);a('input[name="_sku"]',".inline-edit-row").val(d),a('input[name="_regular_price"]',".inline-edit-row").val(u),a('input[name="_sale_price"]',".inline-edit-row").val(v),a('input[name="_weight"]',".inline-edit-row").val(g),a('input[name="_length"]',".inline-edit-row").val(h),a('input[name="_width"]',".inline-edit-row").val(i),a('input[name="_height"]',".inline-edit-row").val(j),a('select[name="_shipping_class"] option:selected',".inline-edit-row").attr("selected",!1).change(),a('select[name="_shipping_class"] option[value="'+k+'"]').attr("selected","selected").change(),a('input[name="_stock"]',".inline-edit-row").val(n),a('input[name="menu_order"]',".inline-edit-row").val(q),a('select[name="_tax_status"] option, select[name="_tax_class"] option, select[name="_visibility"] option, select[name="_stock_status"] option, select[name="_backorders"] option').removeAttr("selected"),a('select[name="_tax_status"] option[value="'+r+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_tax_class"] option[value="'+s+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_visibility"] option[value="'+l+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_stock_status"] option[value="'+m+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_backorders"] option[value="'+t+'"]',".inline-edit-row").attr("selected","selected"),"yes"===o?a('input[name="_featured"]',".inline-edit-row").attr("checked","checked"):a('input[name="_featured"]',".inline-edit-row").removeAttr("checked"),"yes"===p?(a(".stock_qty_field",".inline-edit-row").show().removeAttr("style"),a('input[name="_manage_stock"]',".inline-edit-row").attr("checked","checked")):(a(".stock_qty_field",".inline-edit-row").hide(),a('input[name="_manage_stock"]',".inline-edit-row").removeAttr("checked"));var w=c.find(".product_type").text(),x=c.find(".product_is_virtual").text();"simple"===w||"external"===w?a(".price_fields",".inline-edit-row").show().removeAttr("style"):a(".price_fields",".inline-edit-row").hide(),"yes"===x?a(".dimension_fields",".inline-edit-row").hide():a(".dimension_fields",".inline-edit-row").show().removeAttr("style"),"grouped"===w?a(".stock_fields",".inline-edit-row").hide():a(".stock_fields",".inline-edit-row").show().removeAttr("style")}),a("#the-list").on("change",'.inline-edit-row input[name="_manage_stock"]',function(){a(this).is(":checked")?a(".stock_qty_field",".inline-edit-row").show().removeAttr("style"):a(".stock_qty_field",".inline-edit-row").hide()}),a("#wpbody").on("click","#doaction, #doaction2",function(){a("input.text",".inline-edit-row").val(""),a("#woocommerce-fields").find("select").prop("selectedIndex",0),a("#woocommerce-fields-bulk").find(".inline-edit-group .change-input").hide();var b="product_tag";a('tr.inline-editor textarea[name="tax_input['+b+']"]').suggest(ajaxurl+(ajaxurl.indexOf("?")>0?"&":"?")+"action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:inlineEditL10n.comma})}),a("#wpbody").on("change","#woocommerce-fields-bulk .inline-edit-group .change_to",function(){0<a(this).val()?a(this).closest("div").find(".change-input").show():a(this).closest("div").find(".change-input").hide()})});

View File

@ -84,7 +84,7 @@
Backbone.ajax({
method: 'POST',
dataType: 'json',
url: ajaxurl + ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_tax_rates_save_changes',
url: ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_tax_rates_save_changes',
data: {
current_class: data.current_class,
wc_tax_nonce: data.wc_tax_nonce,

File diff suppressed because one or more lines are too long

View File

@ -1,44 +1,58 @@
/* global woocommerce_settings_params */
jQuery( window ).load( function() {
( function( $ ) {
// Countries
jQuery( 'select#woocommerce_allowed_countries, select#woocommerce_ship_to_countries' ).change( function() {
if ( jQuery( this ).val() === 'specific' ) {
jQuery( this ).parent().parent().next( 'tr' ).show();
// Sell Countries
$( 'select#woocommerce_allowed_countries' ).change( function() {
if ( 'specific' === $( this ).val() ) {
$( this ).closest('tr').next( 'tr' ).hide();
$( this ).closest('tr').next().next( 'tr' ).show();
} else if ( 'all_except' === $( this ).val() ) {
$( this ).closest('tr').next( 'tr' ).show();
$( this ).closest('tr').next().next( 'tr' ).hide();
} else {
jQuery( this ).parent().parent().next( 'tr' ).hide();
$( this ).closest('tr').next( 'tr' ).hide();
$( this ).closest('tr').next().next( 'tr' ).hide();
}
}).change();
// Ship Countries
$( 'select#woocommerce_ship_to_countries' ).change( function() {
if ( 'specific' === $( this ).val() ) {
$( this ).closest('tr').next( 'tr' ).show();
} else {
$( this ).closest('tr').next( 'tr' ).hide();
}
}).change();
// Color picker
jQuery( '.colorpick' ).iris({
$( '.colorpick' ).iris({
change: function( event, ui ) {
jQuery( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
$( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() });
},
hide: true,
border: true
}).click( function() {
jQuery( '.iris-picker' ).hide();
jQuery( this ).closest( 'td' ).find( '.iris-picker' ).show();
$( '.iris-picker' ).hide();
$( this ).closest( 'td' ).find( '.iris-picker' ).show();
});
jQuery( 'body' ).click( function() {
jQuery( '.iris-picker' ).hide();
$( 'body' ).click( function() {
$( '.iris-picker' ).hide();
});
jQuery( '.colorpick' ).click( function( event ) {
$( '.colorpick' ).click( function( event ) {
event.stopPropagation();
});
// Edit prompt
jQuery( function() {
$( function() {
var changed = false;
jQuery( 'input, textarea, select, checkbox' ).change( function() {
$( 'input, textarea, select, checkbox' ).change( function() {
changed = true;
});
jQuery( '.woo-nav-tab-wrapper a' ).click( function() {
$( '.woo-nav-tab-wrapper a' ).click( function() {
if ( changed ) {
window.onbeforeunload = function() {
return woocommerce_settings_params.i18n_nav_warning;
@ -48,13 +62,13 @@ jQuery( window ).load( function() {
}
});
jQuery( '.submit input' ).click( function() {
$( '.submit input' ).click( function() {
window.onbeforeunload = '';
});
});
// Sorting
jQuery( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
$( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({
items: 'tr',
cursor: 'move',
axis: 'y',
@ -62,7 +76,7 @@ jQuery( window ).load( function() {
scrollSensitivity: 40,
helper: function( event, ui ) {
ui.children().each( function() {
jQuery( this ).width( jQuery( this ).width() );
$( this ).width( $( this ).width() );
});
ui.css( 'left', '0' );
return ui;
@ -76,15 +90,15 @@ jQuery( window ).load( function() {
});
// Select all/none
jQuery( '.woocommerce' ).on( 'click', '.select_all', function() {
jQuery( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' );
jQuery( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
$( '.woocommerce' ).on( 'click', '.select_all', function() {
$( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' );
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
return false;
});
jQuery( '.woocommerce' ).on( 'click', '.select_none', function() {
jQuery( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' );
jQuery( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
$( '.woocommerce' ).on( 'click', '.select_none', function() {
$( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' );
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
return false;
});
});
})( jQuery );

View File

@ -1 +1 @@
jQuery(window).load(function(){jQuery("select#woocommerce_allowed_countries, select#woocommerce_ship_to_countries").change(function(){"specific"===jQuery(this).val()?jQuery(this).parent().parent().next("tr").show():jQuery(this).parent().parent().next("tr").hide()}).change(),jQuery(".colorpick").iris({change:function(a,b){jQuery(this).parent().find(".colorpickpreview").css({backgroundColor:b.color.toString()})},hide:!0,border:!0}).click(function(){jQuery(".iris-picker").hide(),jQuery(this).closest("td").find(".iris-picker").show()}),jQuery("body").click(function(){jQuery(".iris-picker").hide()}),jQuery(".colorpick").click(function(a){a.stopPropagation()}),jQuery(function(){var a=!1;jQuery("input, textarea, select, checkbox").change(function(){a=!0}),jQuery(".woo-nav-tab-wrapper a").click(function(){a?window.onbeforeunload=function(){return woocommerce_settings_params.i18n_nav_warning}:window.onbeforeunload=""}),jQuery(".submit input").click(function(){window.onbeforeunload=""})}),jQuery("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(a,b){return b.children().each(function(){jQuery(this).width(jQuery(this).width())}),b.css("left","0"),b},start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),jQuery(".woocommerce").on("click",".select_all",function(){return jQuery(this).closest("td").find("select option").attr("selected","selected"),jQuery(this).closest("td").find("select").trigger("change"),!1}),jQuery(".woocommerce").on("click",".select_none",function(){return jQuery(this).closest("td").find("select option").removeAttr("selected"),jQuery(this).closest("td").find("select").trigger("change"),!1})});
!function(a){a("select#woocommerce_allowed_countries").change(function(){"specific"===a(this).val()?(a(this).closest("tr").next("tr").hide(),a(this).closest("tr").next().next("tr").show()):"all_except"===a(this).val()?(a(this).closest("tr").next("tr").show(),a(this).closest("tr").next().next("tr").hide()):(a(this).closest("tr").next("tr").hide(),a(this).closest("tr").next().next("tr").hide())}).change(),a("select#woocommerce_ship_to_countries").change(function(){"specific"===a(this).val()?a(this).closest("tr").next("tr").show():a(this).closest("tr").next("tr").hide()}).change(),a(".colorpick").iris({change:function(b,c){a(this).parent().find(".colorpickpreview").css({backgroundColor:c.color.toString()})},hide:!0,border:!0}).click(function(){a(".iris-picker").hide(),a(this).closest("td").find(".iris-picker").show()}),a("body").click(function(){a(".iris-picker").hide()}),a(".colorpick").click(function(a){a.stopPropagation()}),a(function(){var b=!1;a("input, textarea, select, checkbox").change(function(){b=!0}),a(".woo-nav-tab-wrapper a").click(function(){b?window.onbeforeunload=function(){return woocommerce_settings_params.i18n_nav_warning}:window.onbeforeunload=""}),a(".submit input").click(function(){window.onbeforeunload=""})}),a("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(b,c){return c.children().each(function(){a(this).width(a(this).width())}),c.css("left","0"),c},start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),a(".woocommerce").on("click",".select_all",function(){return a(this).closest("td").find("select option").attr("selected","selected"),a(this).closest("td").find("select").trigger("change"),!1}),a(".woocommerce").on("click",".select_none",function(){return a(this).closest("td").find("select option").removeAttr("selected"),a(this).closest("td").find("select").trigger("change"),!1})}(jQuery);

View File

@ -1,8 +1,7 @@
/* global shippingClassesLocalizeScript, ajaxurl */
( function( $, data, wp, ajaxurl ) {
$( function() {
var $table = $( '.wc-shipping-classes' ),
$tbody = $( '.wc-shipping-class-rows' ),
var $tbody = $( '.wc-shipping-class-rows' ),
$save_button = $( '.wc-shipping-class-save' ),
$row_template = wp.template( 'wc-shipping-class-row' ),
$blank_template = wp.template( 'wc-shipping-class-row-blank' ),
@ -30,6 +29,17 @@
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 ) {
if ( 'success' === textStatus ) {
if ( response.success ) {
@ -38,12 +48,12 @@
shippingClass.changes = {};
shippingClass.trigger( 'saved:classes' );
} else if ( response.data ) {
window.alert( response.data );
} else {
window.alert( response.data );
} else {
window.alert( data.strings.save_failed );
}
}
shippingClassView.unblock();
shippingClassView.unblock();
}
} ),
@ -87,34 +97,36 @@
// Populate $tbody with the current classes
$.each( classes, function( id, rowData ) {
view.$el.append( view.rowTemplate( rowData ) );
var $tr = view.$el.find( 'tr[data-id="' + rowData.term_id + '"]');
// Editing?
if ( rowData.editing ) {
$tr.addClass( 'editing' );
}
view.renderRow( rowData );
} );
// 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 {
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 ) {
event.data.view.block();
event.data.view.model.save();
@ -131,16 +143,13 @@
newRow = _.extend( {}, data.default_class, {
term_id: 'new-' + size + '-' + Date.now(),
editing: true,
newRow : true
newRow : true
} );
classes[ newRow.term_id ] = newRow;
changes[ newRow.term_id ] = newRow;
model.set( 'classes', classes );
model.logChanges( changes );
view.render();
view.renderRow( newRow );
},
onEditRow: function( event ) {
event.preventDefault();
@ -152,17 +161,39 @@
onDeleteRow: function( event ) {
var view = event.data.view,
model = view.model,
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
row = $( this ).closest('tr'),
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
changes = {},
term_id = $( this ).closest('tr').data('id');
event.preventDefault();
delete classes[ term_id ];
changes[ term_id ] = _.extend( changes[ term_id ] || {}, { deleted : 'deleted' } );
model.set( 'classes', classes );
model.logChanges( changes );
view.render();
if ( classes[ term_id ] ) {
delete classes[ term_id ];
changes[ term_id ] = _.extend( changes[ term_id ] || {}, { deleted : 'deleted' } );
model.set( 'classes', classes );
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() {
this.needsUnloadConfirm = true;
@ -188,10 +219,9 @@
classes = _.indexBy( model.get( 'classes' ), 'term_id' ),
changes = {};
if ( classes[ term_id ][ attribute ] !== value ) {
if ( ! classes[ term_id ] || classes[ term_id ][ attribute ] !== value ) {
changes[ term_id ] = {};
changes[ term_id ][ attribute ] = value;
classes[ term_id ][ attribute ] = value;
}
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

@ -31,16 +31,6 @@
shippingMethod.trigger( 'saved:methods' );
}
},
addMethod: function() {
if ( _.size( this.changes ) && window.confirm( data.strings.save_changes_prompt ) ) {
this.save();
}
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_add_method', {
wc_shipping_zones_nonce : data.wc_shipping_zones_nonce,
method_id : $('select[name="add_method_id"]').val(),
zone_id : data.zone_id
}, this.onAddResponse, 'json' );
},
onSaveResponse: function( response, textStatus ) {
if ( 'success' === textStatus ) {
if ( response.success ) {
@ -52,18 +42,6 @@
window.alert( data.strings.save_failed );
}
}
},
onAddResponse: function( response, textStatus ) {
if ( 'success' === textStatus ) {
if ( response.success && response.data.instance_id ) {
shippingMethod.set( 'methods', response.data.methods );
shippingMethod.trigger( 'change:methods' );
shippingMethod.changes = {};
shippingMethod.trigger( 'saved:methods' );
} else {
window.alert( data.strings.add_method_failed );
}
}
}
} ),
@ -78,11 +56,13 @@
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
$save_button.on( 'click', { view: this }, this.onSubmit );
$('.wc-shipping-zone-add-method').on( 'click', { view: this }, this.onAdd );
// Settings modal
// Settings modals
$( 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( 'wc_backbone_modal_response', this.onConfigureShippingMethodSubmitted );
$( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted );
$( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector );
},
block: function() {
$( this.el ).block({
@ -147,11 +127,6 @@
event.data.view.model.save();
event.preventDefault();
},
onAdd: function( event ) {
event.data.view.block();
event.data.view.model.addMethod();
event.preventDefault();
},
onDeleteRow: function( event ) {
var view = event.data.view,
model = view.model,
@ -301,6 +276,49 @@
error_html = error_html + '</div>';
$( 'table.wc-shipping-zone-methods' ).before( error_html );
},
onAddShippingMethod: function( event ) {
event.preventDefault();
$( this ).WCBackboneModal({
template : 'wc-modal-add-shipping-method',
variable : {
zone_id : data.zone_id
}
});
$( '.wc-shipping-zone-method-selector select' ).change();
},
onAddShippingMethodSubmitted: function( event, target, posted_data ) {
if ( 'wc-modal-add-shipping-method' === target ) {
shippingMethodView.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 : data.zone_id
}, function( response, textStatus ) {
if ( 'success' === textStatus && response.success ) {
// Trigger save if there are changes, or just re-render
if ( _.size( shippingMethodView.model.changes ) ) {
shippingMethodView.model.save();
} else {
shippingMethodView.model.set( 'methods', response.data.methods );
shippingMethodView.model.trigger( 'change:methods' );
shippingMethodView.model.changes = {};
shippingMethodView.model.trigger( 'saved:methods' );
}
}
shippingMethodView.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() );
}
} ),
shippingMethod = new ShippingMethod({

File diff suppressed because one or more lines are too long

View File

@ -28,6 +28,31 @@
this.changes = changes;
this.trigger( 'change:zones' );
},
discardChanges: function( id ) {
var changes = this.changes || {},
set_position = null,
zones = _.indexBy( this.get( 'zones' ), 'zone_id' );
// Find current set position if it has moved since last save
if ( changes[ id ] && changes[ id ].zone_order !== undefined ) {
set_position = changes[ id ].zone_order;
}
// Delete all changes
delete changes[ id ];
// If the position was set, and this zone does exist in DB, set the position again so the changes are not lost.
if ( set_position !== null && zones[ id ] && zones[ id ].zone_order !== set_position ) {
changes[ id ] = _.extend( changes[ id ] || {}, { zone_id : id, zone_order : set_position } );
}
this.changes = changes;
// No changes? Disable save button.
if ( 0 === _.size( this.changes ) ) {
shippingZoneView.clearUnloadConfirmation();
}
},
save: function() {
if ( _.size( this.changes ) ) {
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zones_save_changes', {
@ -63,7 +88,7 @@
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
$save_button.on( 'click', { view: this }, this.onSubmit );
$( document.body ).on( 'click', '.add_shipping_method', { view: this }, this.onAddShippingMethod );
$( 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-save-changes', { view: this }, this.onSubmit );
$( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted );
@ -82,11 +107,11 @@
$( this.el ).unblock();
},
render: function() {
var zones = _.indexBy( this.model.get( 'zones' ), 'zone_id' ),
view = this;
var zones = _.indexBy( this.model.get( 'zones' ), 'zone_id' ),
view = this;
this.$el.empty();
this.unblock();
view.$el.empty();
view.unblock();
if ( _.size( zones ) ) {
// Sort zones
@ -96,56 +121,88 @@
// Populate $tbody with the current zones
$.each( zones, function( id, rowData ) {
view.$el.append( view.rowTemplate( rowData ) );
var $tr = view.$el.find( 'tr[data-id="' + rowData.zone_id + '"]');
// Editing?
if ( rowData.editing ) {
$tr.addClass( 'editing' );
}
// Select values in region select
_.each( rowData.zone_locations, function( location ) {
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 );
}
} );
// List shipping methods
view.renderShippingMethods( rowData.zone_id, rowData.shipping_methods );
view.renderRow( rowData );
} );
// Make the rows function
this.$el.find('.view').show();
this.$el.find('.edit').hide();
this.$el.find('.wc-shipping-zone-save-changes-notice').hide();
this.$el.find( '.wc-shipping-zone-edit' ).on( 'click', { view: this }, this.onEditRow );
this.$el.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow );
this.$el.find( '.wc-shipping-zone-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes );
this.$el.find('.editing .wc-shipping-zone-edit').trigger('click');
// Stripe
if ( 0 === _.size( zones ) % 2) {
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' );
} else {
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
}
} else {
view.$el.append( $blank_template );
}
this.initTooltips();
view.initRows();
},
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.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
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-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() {
// Stripe
if ( 0 === ( $( 'tbody.wc-shipping-zone-rows tr' ).length % 2 ) ) {
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' );
} else {
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
}
// Tooltips
$( '#tiptip_holder' ).removeAttr( 'style' );
$( '#tiptip_arrow' ).removeAttr( 'style' );
$( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 });
},
renderShippingMethods: function( zone_id, shipping_methods ) {
var $tr = $( '.wc-shipping-zones tr[data-id="' + zone_id + '"]');
@ -163,14 +220,10 @@
$method_list.prepend( '<li class="wc-shipping-zone-method"><a href="admin.php?page=wc-settings&amp;tab=shipping&amp;instance_id=' + instance_id + '" class="' + class_name + '">' + shipping_method.title + '</a></li>' );
} );
} else {
$method_list.prepend( '<li class="wc-shipping-zone-method">&ndash;</li>' );
}
},
initTooltips: function() {
$( '#tiptip_holder' ).removeAttr( 'style' );
$( '#tiptip_arrow' ).removeAttr( 'style' );
$( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 });
},
onSubmit: function( event ) {
event.data.view.block();
event.data.view.model.save();
@ -185,8 +238,9 @@
changes = {},
size = _.size( zones ),
newRow = _.extend( {}, data.default_zone, {
zone_id: 'new-' + size + '-' + Date.now(),
editing: true
zone_id : 'new-' + size + '-' + Date.now(),
zone_name: data.strings.default_zone_name,
editing : true
} );
newRow.zone_order = 1 + _.max(
@ -197,13 +251,11 @@
}
);
zones[ newRow.zone_id ] = newRow;
changes[ newRow.zone_id ] = newRow;
model.set( 'zones', zones );
model.logChanges( changes );
view.render();
view.renderRow( newRow );
view.initRows();
},
onTogglePostcodes: function( event ) {
event.preventDefault();
@ -213,37 +265,63 @@
},
onEditRow: function( event ) {
event.preventDefault();
$( this ).closest('tr').addClass('editing');
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');
$( this ).closest('tr').find('.add_shipping_method').attr( 'disabled', 'disabled' ).addClass( 'tips' );
event.data.view.initTooltips();
event.data.view.model.trigger( 'change:zones' );
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 ) {
var view = event.data.view,
model = view.model,
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
changes = {},
row = $( this ).closest('tr'),
zone_id = $( this ).closest('tr').data('id');
event.preventDefault();
delete zones[ zone_id ];
changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { deleted : 'deleted' } );
model.set( 'zones', zones );
model.logChanges( changes );
view.render();
if ( zones[ zone_id ] ) {
delete zones[ zone_id ];
changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { deleted : 'deleted' } );
model.set( 'zones', zones );
model.logChanges( changes );
}
row.remove();
view.initRows();
},
setUnloadConfirmation: function() {
this.needsUnloadConfirm = true;
$save_button.removeAttr( 'disabled' );
$save_button.prop( 'disabled', false );
},
clearUnloadConfirmation: function() {
this.needsUnloadConfirm = false;
$save_button.attr( 'disabled', 'disabled' );
$save_button.prop( 'disabled', true );
},
unloadConfirmation: function( event ) {
if ( event.data.view.needsUnloadConfirm ) {
@ -261,26 +339,32 @@
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
changes = {};
if ( zones[ zone_id ][ attribute ] !== value ) {
if ( ! zones[ zone_id ] || zones[ zone_id ][ attribute ] !== value ) {
changes[ zone_id ] = {};
changes[ zone_id ][ attribute ] = value;
zones[ zone_id ][ attribute ] = value;
}
model.logChanges( changes );
},
updateModelOnSort: function( event ) {
var view = event.data.view,
model = view.model,
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
changes = {};
var view = event.data.view,
model = view.model,
zones = _.indexBy( model.get( 'zones' ), 'zone_id' ),
rows = $( 'tbody.wc-shipping-zone-rows tr' ),
changes = {};
_.each( zones, function( zone ) {
var old_position = parseInt( zone.zone_order, 10 );
var new_position = parseInt( $table.find( 'tr[data-id="' + zone.zone_id + '"]').index(), 10 );
// Update sorted row position
_.each( rows, function( row ) {
var zone_id = $( row ).data( 'id' ),
old_position = null,
new_position = parseInt( $( row ).index(), 10 );
if ( zones[ zone_id ] ) {
old_position = parseInt( zones[ zone_id ].zone_order, 10 );
}
if ( old_position !== new_position ) {
changes[ zone.zone_id ] = _.extend( changes[ zone.zone_id ] || {}, { zone_order : new_position } );
changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { zone_order : new_position } );
}
} );

File diff suppressed because one or more lines are too long

View File

@ -56,7 +56,7 @@ jQuery( function ( $ ) {
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' );
error = 'i18n_mon_decimal_error';
} else if ( $( this ).is( '.wc_input_country_iso' ) ) {
regex = new RegExp( '^([a-zA-Z])?([a-zA-Z])$' );
regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' );
error = 'i18n_country_iso_error';
} else {
regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' );

File diff suppressed because one or more lines are too long

View File

@ -73,7 +73,7 @@
// Reset product data
.on( 'reset_data', function() {
$('.sku').wc_reset_content();
$product.find( '.product_meta' ).find( '.sku' ).wc_reset_content();
$('.product_weight').wc_reset_content();
$('.product_dimensions').wc_reset_content();
$form.trigger( 'reset_image' );

File diff suppressed because one or more lines are too long

View File

@ -63,19 +63,34 @@ jQuery( function( $ ) {
var update_wc_div = function( html_str ) {
var $html = $.parseHTML( html_str );
var $new_form = $( 'table.shop_table.cart', $html ).closest( 'form' );
// Error message collection
var $error = $( '.woocommerce-error', $html );
var $message = $( '.woocommerce-message', $html );
if ( $error.length > 0 ) {
show_notice( $error );
} else if ( $message.length > 0 ) {
show_notice( $message );
} else {
// No new message/error, just remove existing one.
$( '.woocommerce-error, .woocommerce-message' ).remove();
}
// Remove errors
$( '.woocommerce-error, .woocommerce-message' ).remove();
$( 'table.shop_table.cart' ).closest( 'form' ).replaceWith( $new_form );
if ( $new_form.length === 0 ) {
// No items to display now! Replace all cart content.
var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' );
$( 'table.shop_table.cart' ).closest( '.woocommerce' ).replaceWith( $cart_html );
if ( $error.length > 0 ) {
show_notice( $error, $( '.cart-empty' ).closest( '.woocommerce' ) );
} else if ( $message.length > 0 ) {
show_notice( $message, $( '.cart-empty' ).closest( '.woocommerce' ) );
}
} else {
$( 'table.shop_table.cart' ).closest( 'form' ).replaceWith( $new_form );
$( 'table.shop_table.cart' ).closest( 'form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', true );
if ( $error.length > 0 ) {
show_notice( $error );
} else if ( $message.length > 0 ) {
show_notice( $message );
}
}
};
/**
@ -83,11 +98,12 @@ jQuery( function( $ ) {
*
* @param {Object} The Notice HTML Element in string or object form.
*/
var show_notice = function( html_element ) {
var $form = $( 'table.shop_table.cart' ).closest( 'form' );
var show_notice = function( html_element, $target ) {
if ( ! $target ) {
$target = $( 'table.shop_table.cart' ).closest( 'form' );
}
$( '.woocommerce-error, .woocommerce-message' ).remove();
$form.before( html_element );
$target.before( html_element );
};
@ -99,7 +115,8 @@ jQuery( function( $ ) {
/**
* Initialize event handlers and UI state.
*/
init: function() {
init: function( cart ) {
this.cart = cart;
this.toggle_shipping = this.toggle_shipping.bind( this );
this.shipping_method_selected = this.shipping_method_selected.bind( this );
this.shipping_calculator_submit = this.shipping_calculator_submit.bind( this );
@ -166,6 +183,7 @@ jQuery( function( $ ) {
shipping_calculator_submit: function( evt ) {
evt.preventDefault();
var cart = this.cart;
var $form = $( evt.target );
block( $form );
@ -187,6 +205,7 @@ jQuery( function( $ ) {
},
complete: function() {
unblock( $form );
cart.update_cart_totals();
}
} );
}
@ -202,11 +221,16 @@ jQuery( function( $ ) {
init: function() {
this.update_cart_totals = this.update_cart_totals.bind( this );
this.cart_submit = this.cart_submit.bind( this );
this.submit_click = this.submit_click.bind( this );
this.apply_coupon = this.apply_coupon.bind( this );
this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
this.quantity_update = this.quantity_update.bind( this );
this.item_remove_clicked = this.item_remove_clicked.bind( this );
$( document ).on(
'click',
'div.woocommerce > form input[type=submit]',
this.submit_click );
$( document ).on(
'submit',
'div.woocommerce > form',
@ -219,6 +243,19 @@ jQuery( function( $ ) {
'click',
'td.product-remove > a',
this.item_remove_clicked );
$( document ).on(
'change input',
'div.woocommerce > form .cart_item :input',
this.input_changed );
$( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', true );
},
/**
* After an input is changed, enable the update cart button.
*/
input_changed: function() {
$( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', false );
},
/**
@ -246,6 +283,7 @@ jQuery( function( $ ) {
var $form = $( evt.target );
var $submit = $( document.activeElement );
var $clicked = $( 'input[type=submit][clicked=true]' );
if ( 0 === $form.find( 'table.shop_table.cart' ).length ) {
return false;
@ -254,14 +292,24 @@ jQuery( function( $ ) {
return false;
}
if ( $submit.is( '[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) {
if ( $clicked.is( '[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) {
this.quantity_update( $form );
} else if ( $submit.is( '[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) {
} else if ( $clicked.is( '[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) {
this.apply_coupon( $form );
}
},
/**
* Special handling to identify which submit button was clicked.
*
* @param {Object} evt The JQuery event
*/
submit_click: function( evt ) {
$( 'input[type=submit]', $( evt.target ).parents( 'form' ) ).removeAttr( 'clicked' );
$( evt.target ).attr( 'clicked', 'true' );
},
/**
* Apply Coupon code
*
@ -286,6 +334,7 @@ jQuery( function( $ ) {
dataType: 'html',
success: function( response ) {
show_notice( response );
$( document.body ).trigger( 'applied_coupon' );
},
complete: function() {
unblock( $form );
@ -321,6 +370,7 @@ jQuery( function( $ ) {
dataType: 'html',
success: function( response ) {
show_notice( response );
$( document.body ).trigger( 'removed_coupon' );
unblock( $tr.parents( 'table' ) );
},
complete: function() {
@ -336,6 +386,8 @@ jQuery( function( $ ) {
*/
quantity_update: function( $form ) {
var cart = this;
// Provide the submit button value because wc-form-handler expects it.
$( '<input />' ).attr( 'type', 'hidden' )
.attr( 'name', 'update_cart' )
@ -353,6 +405,7 @@ jQuery( function( $ ) {
success: update_wc_div,
complete: function() {
unblock( $form );
cart.update_cart_totals();
}
} );
},
@ -365,6 +418,7 @@ jQuery( function( $ ) {
item_remove_clicked: function( evt ) {
evt.preventDefault();
var cart = this;
var $a = $( evt.target );
var $form = $a.parents( 'form' );
@ -377,11 +431,12 @@ jQuery( function( $ ) {
success: update_wc_div,
complete: function() {
unblock( $form );
cart.update_cart_totals();
}
} );
}
};
cart_shipping.init();
cart_shipping.init( cart );
cart.init();
} );

File diff suppressed because one or more lines are too long

View File

@ -68,7 +68,7 @@ jQuery( function( $ ) {
} );
// Don't show the "use new" radio button if we are a guest or only have one method..
if ( 0 === $( '#wc-' + woocommerceTokenizationParams.gatewayID + '-method-count' ).data( 'count' ) || ! woocommerceTokenizationParams.userLoggedIn ) {
if ( 0 === $( '#wc-' + woocommerceTokenizationParams.gatewayID + '-methods' ).data( 'count' ) || ! woocommerceTokenizationParams.userLoggedIn ) {
$( '.wc-' + woocommerceTokenizationParams.gatewayID + '-payment-form-new-checkbox-wrap' ).hide();
}

View File

@ -1 +1 @@
jQuery(function(a){var b={gatewayID:woocommerceTokenizationParams.gatewayID,userLoggedIn:woocommerceTokenizationParams.userLoggedIn,hideForm:function(){a("#wc-"+this.gatewayID+"-cc-form, #wc-"+this.gatewayID+"-echeck-form").hide()},showForm:function(){a("#wc-"+this.gatewayID+"-cc-form, #wc-"+this.gatewayID+"-echeck-form").show()},showSaveNewCheckbox:function(){a("#wc-"+this.gatewayID+"-new-payment-method-wrap").show()},hideSaveNewCheckbox:function(){a("#wc-"+this.gatewayID+"-new-payment-method-wrap").hide()},showSaveNewCheckboxForLoggedInOnly:function(){this.userLoggedIn?a("#wc-"+this.gatewayID+"-new-payment-method-wrap").show():a("#wc-"+this.gatewayID+"-new-payment-method-wrap").hide()}};a(document.body).on("updated_checkout",function(){a('input[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]').is(":checked")?(b.hideForm(),b.hideSaveNewCheckbox()):(a('input:radio[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]:first').attr("checked",!0),"new"===a('input:radio[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]:first').val()?(b.showForm(),b.showSaveNewCheckboxForLoggedInOnly()):(b.hideForm(),b.hideSaveNewCheckbox())),a('input[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]').change(function(){"new"===a('input[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]:checked').val()?(b.showForm(),b.showSaveNewCheckboxForLoggedInOnly()):(b.hideForm(),b.hideSaveNewCheckbox())}),a("input#createaccount").change(function(){a(this).is(":checked")?b.showSaveNewCheckbox():b.hideSaveNewCheckbox()}),0!==a("#wc-"+woocommerceTokenizationParams.gatewayID+"-method-count").data("count")&&woocommerceTokenizationParams.userLoggedIn||a(".wc-"+woocommerceTokenizationParams.gatewayID+"-payment-form-new-checkbox-wrap").hide()})});
jQuery(function(a){var b={gatewayID:woocommerceTokenizationParams.gatewayID,userLoggedIn:woocommerceTokenizationParams.userLoggedIn,hideForm:function(){a("#wc-"+this.gatewayID+"-cc-form, #wc-"+this.gatewayID+"-echeck-form").hide()},showForm:function(){a("#wc-"+this.gatewayID+"-cc-form, #wc-"+this.gatewayID+"-echeck-form").show()},showSaveNewCheckbox:function(){a("#wc-"+this.gatewayID+"-new-payment-method-wrap").show()},hideSaveNewCheckbox:function(){a("#wc-"+this.gatewayID+"-new-payment-method-wrap").hide()},showSaveNewCheckboxForLoggedInOnly:function(){this.userLoggedIn?a("#wc-"+this.gatewayID+"-new-payment-method-wrap").show():a("#wc-"+this.gatewayID+"-new-payment-method-wrap").hide()}};a(document.body).on("updated_checkout",function(){a('input[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]').is(":checked")?(b.hideForm(),b.hideSaveNewCheckbox()):(a('input:radio[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]:first').attr("checked",!0),"new"===a('input:radio[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]:first').val()?(b.showForm(),b.showSaveNewCheckboxForLoggedInOnly()):(b.hideForm(),b.hideSaveNewCheckbox())),a('input[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]').change(function(){"new"===a('input[name="wc-'+woocommerceTokenizationParams.gatewayID+'-payment-token"]:checked').val()?(b.showForm(),b.showSaveNewCheckboxForLoggedInOnly()):(b.hideForm(),b.hideSaveNewCheckbox())}),a("input#createaccount").change(function(){a(this).is(":checked")?b.showSaveNewCheckbox():b.hideSaveNewCheckbox()}),0!==a("#wc-"+woocommerceTokenizationParams.gatewayID+"-methods").data("count")&&woocommerceTokenizationParams.userLoggedIn||a(".wc-"+woocommerceTokenizationParams.gatewayID+"-payment-form-new-checkbox-wrap").hide()})});

View File

@ -18,7 +18,7 @@ return array(
'AF' => array(
'name' => __( 'Africa', 'woocommerce' ),
'countries' => array(
'AO', 'BF', 'BI', 'BJ', 'BW', 'CD', 'CF', 'CG', 'CI', 'CM', 'CV', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'ET', 'GA', 'GH', 'GM', 'GN', 'GQ', 'GW', 'KE', 'KM', 'LR', 'LS', 'LY', 'MA', 'MG', 'ML', 'MR', 'MU', 'MW', 'MZ', 'NA', 'NE', 'NG', 'RE', 'RW', 'SC', 'SD', 'SH', 'SL', 'SN', 'SO', 'ST', 'SZ', 'TD', 'TG', 'TN', 'TZ', 'UG', 'YT', 'ZA', 'ZM', 'ZW'
'AO', 'BF', 'BI', 'BJ', 'BW', 'CD', 'CF', 'CG', 'CI', 'CM', 'CV', 'DJ', 'DZ', 'EG', 'EH', 'ER', 'ET', 'GA', 'GH', 'GM', 'GN', 'GQ', 'GW', 'KE', 'KM', 'LR', 'LS', 'LY', 'MA', 'MG', 'ML', 'MR', 'MU', 'MW', 'MZ', 'NA', 'NE', 'NG', 'RE', 'RW', 'SC', 'SD', 'SS', 'SH', 'SL', 'SN', 'SO', 'ST', 'SZ', 'TD', 'TG', 'TN', 'TZ', 'UG', 'YT', 'ZA', 'ZM', 'ZW'
)
),
'AN' => array(

File diff suppressed because it is too large Load Diff

View File

@ -84,7 +84,7 @@ return array(
'country' => 'CA',
'state' => 'BC',
'rate' => '7.0000',
'name' => 'PST',
'name' => _x( 'PST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => false,
'priority' => 2
)
@ -94,7 +94,7 @@ return array(
'country' => 'CA',
'state' => 'SK',
'rate' => '5.0000',
'name' => 'PST',
'name' => _x( 'PST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => false,
'priority' => 2
)
@ -104,7 +104,7 @@ return array(
'country' => 'CA',
'state' => 'MB',
'rate' => '8.0000',
'name' => 'PST',
'name' => _x( 'PST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => false,
'priority' => 2
)
@ -114,7 +114,7 @@ return array(
'country' => 'CA',
'state' => 'QC',
'rate' => '9.975',
'name' => 'QST',
'name' => _x( 'QST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => false,
'priority' => 2
)
@ -124,91 +124,91 @@ return array(
'country' => 'CA',
'state' => 'ON',
'rate' => '13.0000',
'name' => 'HST',
'name' => _x( 'HST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'NL',
'rate' => '13.0000',
'name' => 'HST',
'name' => _x( 'HST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'NB',
'rate' => '13.0000',
'name' => 'HST',
'name' => _x( 'HST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'PE',
'rate' => '14.0000',
'name' => 'HST',
'name' => _x( 'HST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'NS',
'rate' => '15.0000',
'name' => 'HST',
'name' => _x( 'HST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'AB',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'BC',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'NT',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'NU',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'YT',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'SK',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'MB',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
),
array(
'country' => 'CA',
'state' => 'QC',
'rate' => '5.0000',
'name' => 'GST',
'name' => _x( 'GST', 'Canadian Tax Rates', 'woocommerce' ),
'shipping' => true
)
)

View File

@ -663,9 +663,11 @@ abstract class WC_Abstract_Order {
* @return bool success or fail.
*/
public function calculate_taxes() {
$tax_total = 0;
$taxes = array();
$tax_based_on = get_option( 'woocommerce_tax_based_on' );
$tax_total = 0;
$shipping_tax_total = 0;
$taxes = array();
$shipping_taxes = array();
$tax_based_on = get_option( 'woocommerce_tax_based_on' );
// If is_vat_exempt is 'yes', or wc_tax_enabled is false, return and do nothing.
if ( 'yes' === $this->is_vat_exempt or ! wc_tax_enabled() ) {
@ -729,32 +731,51 @@ abstract class WC_Abstract_Order {
}
}
// Now calculate shipping tax
$shipping_methods = $this->get_shipping_methods();
if ( ! empty( $shipping_methods ) ) {
$matched_tax_rates = array();
$tax_rates = WC_Tax::find_rates( array(
'country' => $country,
'state' => $state,
'postcode' => $postcode,
'city' => $city,
'tax_class' => ''
) );
if ( ! empty( $tax_rates ) ) {
foreach ( $tax_rates as $key => $rate ) {
if ( isset( $rate['shipping'] ) && 'yes' === $rate['shipping'] ) {
$matched_tax_rates[ $key ] = $rate;
// Calc taxes for shipping
foreach ( $this->get_shipping_methods() as $item_id => $item ) {
$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
// Inherit tax class from items
if ( '' === $shipping_tax_class ) {
$tax_classes = WC_Tax::get_tax_classes();
foreach ( $tax_classes as $tax_class ) {
$tax_class = sanitize_title( $tax_class );
if ( in_array( $tax_class, $found_tax_classes ) ) {
$tax_rates = WC_Tax::find_shipping_rates( array(
'country' => $args['country'],
'state' => $args['state'],
'postcode' => $args['postcode'],
'city' => $args['city'],
'tax_class' => $tax_class,
) );
break;
}
}
} else {
$tax_rates = WC_Tax::find_shipping_rates( array(
'country' => $args['country'],
'state' => $args['state'],
'postcode' => $args['postcode'],
'city' => $args['city'],
'tax_class' => 'standard' === $shipping_tax_class ? '' : $shipping_tax_class,
) );
}
$shipping_taxes = WC_Tax::calc_shipping_tax( $this->order_shipping, $matched_tax_rates );
$shipping_tax_total = WC_Tax::round( array_sum( $shipping_taxes ) );
} else {
$shipping_taxes = array();
$shipping_tax_total = 0;
$line_taxes = WC_Tax::calc_tax( $item->get_total(), $tax_rates, false );
$line_tax = max( 0, array_sum( $line_taxes ) );
$shipping_tax_total += $line_tax;
wc_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $line_tax ) );
wc_update_order_item_meta( $item_id, '_line_tax_data', array( 'total' => $line_taxes ) );
// Sum the item taxes
foreach ( array_keys( $shipping_taxes + $line_taxes ) as $key ) {
$shipping_taxes[ $key ] = ( isset( $line_taxes[ $key ] ) ? $line_taxes[ $key ] : 0 ) + ( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 0 );
}
}
// Save tax totals
@ -1661,7 +1682,7 @@ abstract class WC_Abstract_Order {
$shipping_methods = $this->get_shipping_methods();
foreach ( $shipping_methods as $shipping ) {
$labels[] = $shipping['name'];
$labels[] = $shipping['name'] ? $shipping['name'] : __( 'Shipping', 'woocommerce' );
}
}
@ -2006,7 +2027,7 @@ abstract class WC_Abstract_Order {
$args = wp_parse_args( $args, $defaults );
$template = $args['plain_text'] ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php';
wc_get_template( $template, array(
wc_get_template( $template, apply_filters( 'woocommerce_email_order_items_args', array(
'order' => $this,
'items' => $this->get_items(),
'show_download_links' => $this->is_download_permitted() && ! $args['sent_to_admin'],
@ -2016,7 +2037,7 @@ abstract class WC_Abstract_Order {
'image_size' => $args['image_size'],
'plain_text' => $args['plain_text'],
'sent_to_admin' => $args['sent_to_admin']
) );
) ) );
return apply_filters( 'woocommerce_email_order_items_table', ob_get_clean(), $this );
}
@ -2338,7 +2359,7 @@ abstract class WC_Abstract_Order {
}
if ( ! wp_update_post( $update_post_data ) ) {
$this->add_order_note( sprintf( __( 'Unable to update order from %s to %s.', 'woocommerce' ), wc_get_order_status_name( $old_status ), wc_get_order_status_name( $new_status ) ), 0, $manual );
$this->add_order_note( sprintf( __( 'Unable to update order from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $old_status ), wc_get_order_status_name( $new_status ) ), 0, $manual );
return false;
}
@ -2347,7 +2368,7 @@ abstract class WC_Abstract_Order {
// Status was changed.
if ( $new_status !== $old_status ) {
$this->add_order_note( trim( $note . ' ' . sprintf( __( 'Order status changed from %s to %s.', 'woocommerce' ), wc_get_order_status_name( $old_status ), wc_get_order_status_name( $new_status ) ) ), 0, $manual );
$this->add_order_note( trim( $note . ' ' . sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $old_status ), wc_get_order_status_name( $new_status ) ) ), 0, $manual );
do_action( 'woocommerce_order_status_' . $old_status . '_to_' . $new_status, $this->id );
do_action( 'woocommerce_order_status_changed', $this->id, $old_status, $new_status );
} else {
@ -2594,9 +2615,9 @@ abstract class WC_Abstract_Order {
$item_name = $_product->get_sku() ? $_product->get_sku(): $item['product_id'];
if ( isset( $item['variation_id'] ) && $item['variation_id'] ) {
$this->add_order_note( sprintf( __( 'Item %s variation #%s stock reduced from %s to %s.', 'woocommerce' ), $item_name, $item['variation_id'], $new_stock + $qty, $new_stock) );
$this->add_order_note( sprintf( __( 'Item %1$s variation #%2$s stock reduced from %3$s to %4$s.', 'woocommerce' ), $item_name, $item['variation_id'], $new_stock + $qty, $new_stock) );
} else {
$this->add_order_note( sprintf( __( 'Item %s stock reduced from %s to %s.', 'woocommerce' ), $item_name, $new_stock + $qty, $new_stock) );
$this->add_order_note( sprintf( __( 'Item %1$s stock reduced from %2$s to %3$s.', 'woocommerce' ), $item_name, $new_stock + $qty, $new_stock) );
}
$this->send_stock_notifications( $_product, $new_stock, $item['qty'] );
}
@ -2716,6 +2737,6 @@ abstract class WC_Abstract_Order {
* @return bool
*/
public function is_editable() {
return apply_filters( 'wc_order_is_editable', in_array( $this->get_status(), array( 'pending', 'on-hold', 'auto-draft' ) ), $this );
return apply_filters( 'wc_order_is_editable', in_array( $this->get_status(), array( 'pending', 'on-hold', 'auto-draft', 'failed' ) ), $this );
}
}

View File

@ -125,7 +125,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
return $this->tokens;
}
if ( is_user_logged_in() && $this->supports( 'tokenization' ) && is_checkout() ) {
if ( is_user_logged_in() && $this->supports( 'tokenization' ) ) {
$this->tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), $this->id );
}
@ -382,12 +382,12 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
* @since 2.6.0
*/
public function saved_payment_methods() {
$html = '<p>';
$html = '<ul id="wc-' . esc_attr( $this->id ) . '-methods" class="wc-saved-payment-methods" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '">';
foreach ( $this->get_tokens() as $token ) {
$html .= $this->saved_payment_method( $token );
$html .= '<li>' . $this->saved_payment_method( $token ) . '</li>';
}
$html .= '</p><span id="wc-' . esc_attr( $this->id ) . '-method-count" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '"></span>';
$html .= '<div class="clear"></div>';
$html .= '<li class="wc-' . esc_attr( $this->id ) . '-payment-form-new-checkbox-wrap">' . $this->use_new_payment_method_checkbox() . '</li>';
$html .= '</ul>';
echo apply_filters( 'wc_payment_gateway_form_saved_payment_methods_html', $html, $this );
}
@ -411,7 +411,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
);
$html .= $this->saved_payment_method_title( $token );
$html .= '</label><br />';
$html .= '</label>';
return apply_filters( 'wc_payment_gateway_form_saved_payment_method_html', $html, $token, $this );
}
@ -474,9 +474,9 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
$label = ( ! empty( $this->new_method_label ) ? esc_html( $this->new_method_label ) : esc_html__( 'Use a new payment method', 'woocommerce' ) );
$html = '<input type="radio" id="wc-' . esc_attr( $this->id ). '-new" name="wc-' . esc_attr( $this->id ) . '-payment-token" value="new" style="width:auto;">';
$html .= '<label class="wc-' . esc_attr( $this->id ) . '-payment-form-new-checkbox wc-gateway-payment-token-label" for="wc-' . esc_attr( $this->id ) . '-new">';
$html .= apply_filters( 'woocommerce_payment_gateway_form_new_method_label', $label, $this );
$html .= apply_filters( 'woocommerce_payment_gateway_form_new_method_label', $label, $this );
$html .= '</label>';
echo '<div class="wc-' . esc_attr( $this->id ) . '-payment-form-new-checkbox-wrap">' . $html . '</div>';
return $html;
}
/**
@ -491,5 +491,4 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
$cc_form->supports = $this->supports;
$cc_form->form();
}
}

View File

@ -610,16 +610,20 @@ class WC_Product {
* @return bool
*/
public function is_in_stock() {
$status = false;
if ( $this->managing_stock() && $this->backorders_allowed() ) {
$status = true;
} elseif ( $this->managing_stock() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
$status = $this->stock_status === 'instock';
/**
* Sanity check to ensure stock qty is not lower than 0 but still listed
* instock.
*
* Check is not required for products on backorder since they can be
* instock regardless of actual stock quantity.
*/
if ( $this->managing_stock() && ! $this->backorders_allowed() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) {
$status = false;
} else {
$status = $this->stock_status === 'instock';
}
return apply_filters( 'woocommerce_product_is_in_stock', $status);
return apply_filters( 'woocommerce_product_is_in_stock', $status );
}
/**
@ -666,61 +670,44 @@ class WC_Product {
* @return string
*/
public function get_availability() {
$availability = $class = '';
if ( $this->managing_stock() ) {
if ( $this->is_in_stock() && $this->get_total_stock() > get_option( 'woocommerce_notify_no_stock_amount' ) ) {
switch ( get_option( 'woocommerce_stock_format' ) ) {
case 'no_amount' :
$availability = __( 'In stock', 'woocommerce' );
break;
case 'low_amount' :
if ( $this->get_total_stock() <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
$availability = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $this->get_total_stock() );
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
$availability .= ' ' . __( '(can be backordered)', 'woocommerce' );
}
} else {
$availability = __( 'In stock', 'woocommerce' );
}
break;
default :
$availability = sprintf( __( '%s in stock', 'woocommerce' ), $this->get_total_stock() );
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
$availability .= ' ' . __( '(can be backordered)', 'woocommerce' );
}
break;
}
$class = 'in-stock';
} elseif ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
$availability = __( 'Available on backorder', 'woocommerce' );
$class = 'available-on-backorder';
} elseif ( $this->backorders_allowed() ) {
$availability = __( 'In stock', 'woocommerce' );
$class = 'in-stock';
} else {
$availability = __( 'Out of stock', 'woocommerce' );
$class = 'out-of-stock';
}
} elseif ( ! $this->is_in_stock() ) {
// Default to in-stock
$availability = __( 'In stock', 'woocommerce' );
$class = 'in-stock';
// If out of stock, this takes priority over all other settings.
if ( ! $this->is_in_stock() ) {
$availability = __( 'Out of stock', 'woocommerce' );
$class = 'out-of-stock';
// Any further we can assume status is set to in stock.
} elseif ( $this->managing_stock() && $this->is_on_backorder( 1 ) ) {
$availability = __( 'Available on backorder', 'woocommerce' );
$class = 'available-on-backorder';
} elseif ( $this->managing_stock() ) {
switch ( get_option( 'woocommerce_stock_format' ) ) {
case 'no_amount' :
$availability = __( 'In stock', 'woocommerce' );
break;
case 'low_amount' :
if ( $this->get_total_stock() <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
$availability = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $this->get_total_stock() );
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
$availability .= ' ' . __( '(also available on backorder)', 'woocommerce' );
}
} else {
$availability = __( 'In stock', 'woocommerce' );
}
break;
default :
$availability = sprintf( __( '%s in stock', 'woocommerce' ), $this->get_total_stock() );
if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
$availability .= ' ' . __( '(also available on backorder)', 'woocommerce' );
}
break;
}
}
return apply_filters( 'woocommerce_get_availability', array( 'availability' => $availability, 'class' => $class ), $this );
@ -1557,14 +1544,13 @@ class WC_Product {
* @return string Formatted product name
*/
public function get_formatted_name() {
if ( $this->get_sku() ) {
$identifier = $this->get_sku();
} else {
$identifier = '#' . $this->id;
}
return sprintf( __( '%s &ndash; %s', 'woocommerce' ), $identifier, $this->get_title() );
return sprintf( '%s &ndash; %s', $identifier, $this->get_title() );
}
/**

View File

@ -0,0 +1,175 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Abstract Rest Controler Class
*
* @author WooThemes
* @category API
* @package WooCommerce/Abstracts
* @extends WP_REST_Controller
* @version 2.6.0
*/
abstract class WC_REST_Controller extends WP_REST_Controller {
/**
* Endpoint namespace.
*
* @var string
*/
protected $namespace = 'wc/v1';
/**
* Route base.
*
* @var string
*/
protected $rest_base = '';
/**
* Get normalized rest base.
*
* @return string
*/
protected function get_normalized_rest_base() {
return preg_replace( '/\(.*\)\//i', '', $this->rest_base );
}
/**
* Check batch limit.
*
* @param array $items Request items.
* @return bool|WP_Error
*/
protected function check_batch_limit( $items ) {
$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
$total = 0;
if ( ! empty( $items['create'] ) ) {
$total += count( $items['create'] );
}
if ( ! empty( $items['update'] ) ) {
$total += count( $items['update'] );
}
if ( ! empty( $items['delete'] ) ) {
$total += count( $items['delete'] );
}
if ( $total > $limit ) {
return new WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) );
}
return true;
}
/**
* Bulk create, update and delete items.
*
* @param WP_REST_Request $request Full details about the request.
* @return array Of WP_Error or WP_REST_Response.
*/
public function batch_items( $request ) {
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
// Get the request params.
$items = array_filter( $request->get_params() );
$response = array();
// Check batch limit.
$limit = $this->check_batch_limit( $items );
if ( is_wp_error( $limit ) ) {
return $limit;
}
if ( ! empty( $items['create'] ) ) {
foreach ( $items['create'] as $item ) {
$_item = new WP_REST_Request( 'POST' );
$_item->set_body_params( $item );
$_response = $this->create_item( $_item );
if ( is_wp_error( $_response ) ) {
$response['create'][] = array(
'id' => 0,
'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
);
} else {
$response['create'][] = $wp_rest_server->response_to_data( $_response, '' );
}
}
}
if ( ! empty( $items['update'] ) ) {
foreach ( $items['update'] as $item ) {
$_item = new WP_REST_Request( 'PUT' );
$_item->set_body_params( $item );
$_response = $this->update_item( $_item );
if ( is_wp_error( $_response ) ) {
$response['update'][] = array(
'id' => $item['id'],
'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
);
} else {
$response['update'][] = $wp_rest_server->response_to_data( $_response, '' );
}
}
}
if ( ! empty( $items['delete'] ) ) {
foreach ( $items['delete'] as $id ) {
$_item = new WP_REST_Request( 'DELETE' );
$_item->set_query_params( array( 'id' => $id, 'force' => true ) );
$_response = $this->delete_item( $_item );
if ( is_wp_error( $_response ) ) {
$response['delete'][] = array(
'id' => $id,
'error' => array( 'code' => $_response->get_error_code(), 'message' => $_response->get_error_message(), 'data' => $_response->get_error_data() ),
);
} else {
$response['delete'][] = $wp_rest_server->response_to_data( $_response, '' );
}
}
}
return $response;
}
/**
* Get the batch schema, conforming to JSON Schema.
*
* @return array
*/
public function get_public_batch_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'batch',
'type' => 'object',
'properties' => array(
'create' => array(
'description' => __( 'List of created resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
),
'update' => array(
'description' => __( 'List of updated resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
),
'delete' => array(
'description' => __( 'List of delete resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
),
),
);
return $schema;
}
}

View File

@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @package WooCommerce/Abstracts
* @version 2.6.0
*/
abstract class WC_REST_Posts_Controller extends WP_REST_Controller {
abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.
@ -118,6 +118,20 @@ abstract class WC_REST_Posts_Controller extends WP_REST_Controller {
return true;
}
/**
* Check if a given request has access batch create, update and delete items.
*
* @param WP_REST_Request $request Full details about the request.
* @return boolean
*/
public function batch_items_permissions_check( $request ) {
if ( ! wc_rest_check_post_permissions( $this->post_type, 'batch' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to manipule this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
/**
* Get a single item.
*

View File

@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @package WooCommerce/Abstracts
* @version 2.6.0
*/
abstract class WC_REST_Terms_Controller extends WP_REST_Controller {
abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
/**
* Route base.
@ -80,6 +80,16 @@ abstract class WC_REST_Terms_Controller extends WP_REST_Controller {
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );
}
/**
@ -177,6 +187,25 @@ abstract class WC_REST_Terms_Controller extends WP_REST_Controller {
return true;
}
/**
* Check if a given request has access batch create, update and delete items.
*
* @param WP_REST_Request $request Full details about the request.
* @return boolean
*/
public function batch_items_permissions_check( $request ) {
$permissions = $this->check_permissions( $request, 'batch' );
if ( is_wp_error( $permissions ) ) {
return $permissions;
}
if ( ! $permissions ) {
return new WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to manipule this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
/**
* Check permissions.
*

View File

@ -42,6 +42,12 @@ abstract class WC_Settings_API {
*/
public $form_fields = array();
/**
* The posted settings data. When empty, $_POST data will be used.
* @var array
*/
protected $data = array();
/**
* Get the form fields after they are initialized.
* @return array of options
@ -122,18 +128,35 @@ abstract class WC_Settings_API {
return $this->validate_text_field( $key, $value );
}
/**
* Sets the POSTed data. This method can be used to set specific data, instead
* of taking it from the $_POST array.
* @param array data
*/
public function set_post_data( $data = array() ) {
$this->data = $data;
}
/**
* Returns the POSTed data, to be used to save the settings.
* @return array
*/
public function get_post_data() {
if ( ! empty( $this->data ) && is_array( $this->data ) ) {
return $this->data;
}
return $_POST;
}
/**
* Processes and saves options.
* If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.
* @param array $post_data Defaults to $_POST but can be passed in.
* @return bool was anything saved?
*/
public function process_admin_options( $post_data = array() ) {
public function process_admin_options() {
$this->init_settings();
if ( empty( $post_data ) ) {
$post_data = $_POST;
}
$post_data = $this->get_post_data();
foreach ( $this->get_form_fields() as $key => $field ) {
if ( 'title' !== $this->get_field_type( $field ) ) {

View File

@ -207,19 +207,40 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
return $this->rates;
}
/**
* Returns a rate ID based on this methods ID and instance, with an optional
* suffix if distinguishing between multiple rates.
* @since 2.6.0
* @param string $suffix
* @return string
*/
public function get_rate_id( $suffix = '' ) {
$rate_id = array( $this->id );
if ( $this->instance_id ) {
$rate_id[] = $this->instance_id;
}
if ( $suffix ) {
$rate_id[] = $suffix;
}
return implode( ':', $rate_id );
}
/**
* Add a shipping rate. If taxes are not set they will be calculated based on cost.
* @param array $args (default: array())
* @param array $package option to store information about the package in meta.
*/
public function add_rate( $args = array(), $package = false ) {
public function add_rate( $args = array() ) {
$args = wp_parse_args( $args, array(
'id' => '', // ID for the rate
'id' => $this->get_rate_id(), // ID for the rate. If not passed, this id:instance default will be used.
'label' => '', // Label for the rate
'cost' => '0', // Amount or array of costs (per item shipping)
'taxes' => '', // Pass taxes, or leave empty to have it calculated for you, or 'false' to disable calculations
'calc_tax' => 'per_order', // Calc tax per_order or per_item. Per item needs an array of costs
'meta_data' => array() // Array of misc meta data to store along with this rate - key value pairs.
'meta_data' => array(), // Array of misc meta data to store along with this rate - key value pairs.
'package' => false, // Package array this rate was generated for @since 2.6.0
) );
// ID and label are required
@ -249,9 +270,9 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
}
// Store package data
if ( $package ) {
if ( $args['package'] ) {
$items_in_package = array();
foreach ( $package['contents'] as $item ) {
foreach ( $args['package']['contents'] as $item ) {
$product = $item['data'];
$items_in_package[] = $product->get_title() . ' &times; ' . $item['quantity'];
}
@ -462,16 +483,13 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
* Processes and saves options.
* If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.
* @since 2.6.0
* @param array $post_data Defaults to $_POST but can be passed in.
* @return bool was anything saved?
*/
public function process_admin_options( $post_data = array() ) {
public function process_admin_options() {
if ( $this->instance_id ) {
$this->init_instance_settings();
if ( empty( $post_data ) ) {
$post_data = $_POST;
}
$post_data = $this->get_post_data();
foreach ( $this->get_instance_form_fields() as $key => $field ) {
if ( 'title' !== $this->get_field_type( $field ) ) {

View File

@ -161,7 +161,7 @@ class WC_Admin_Assets {
// Products
if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
wp_register_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), WC_VERSION );
wp_enqueue_script( 'woocommerce_quick-edit' );
}
@ -208,11 +208,8 @@ class WC_Admin_Assets {
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
wp_register_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
wp_register_script( 'wc-admin-order-meta-boxes-modal', WC()->plugin_url() . '/assets/js/admin/order-backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util', 'wc-admin-order-meta-boxes' ), WC_VERSION );
wp_register_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-order-meta-boxes' );
wp_enqueue_script( 'wc-admin-order-meta-boxes-modal' );
$params = array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
@ -286,7 +283,8 @@ class WC_Admin_Assets {
'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),
'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ),
'i18n_product_type_alert' => __( 'Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports.', 'woocommerce' )
'i18n_product_type_alert' => __( 'Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports.', 'woocommerce' ),
'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' )
);
wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );

View File

@ -167,11 +167,19 @@ class WC_Admin_Attributes {
);
// Update taxonomy ordering term meta
$wpdb->update(
$wpdb->prefix . 'woocommerce_termmeta',
array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ),
array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) )
);
if ( get_option( 'db_version' ) < 34370 ) {
$wpdb->update(
$wpdb->prefix . 'woocommerce_termmeta',
array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ),
array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) )
);
} else {
$wpdb->update(
$wpdb->termmeta,
array( 'meta_key' => 'order_pa_' . sanitize_title( $attribute['attribute_name'] ) ),
array( 'meta_key' => 'order_pa_' . sanitize_title( $old_attribute_name ) )
);
}
// Update product attributes which use this taxonomy
$old_attribute_name_length = strlen( $old_attribute_name ) + 3;
@ -204,15 +212,17 @@ class WC_Admin_Attributes {
*/
private static function process_delete_attribute() {
global $wpdb;
$attribute_id = absint( $_GET['delete'] );
check_admin_referer( 'woocommerce-delete-attribute_' . $attribute_id );
$attribute_name = $wpdb->get_var( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" );
$taxonomy = wc_attribute_taxonomy_name( $attribute_name );
do_action( 'woocommerce_before_attribute_delete', $attribute_id, $attribute_name, $taxonomy );
if ( $attribute_name && $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ) ) {
$taxonomy = wc_attribute_taxonomy_name( $attribute_name );
if ( taxonomy_exists( $taxonomy ) ) {
$terms = get_terms( $taxonomy, 'orderby=name&hide_empty=0' );
foreach ( $terms as $term ) {
@ -222,7 +232,6 @@ class WC_Admin_Attributes {
do_action( 'woocommerce_attribute_deleted', $attribute_id, $attribute_name, $taxonomy );
delete_transient( 'wc_attribute_taxonomies' );
return true;
}

View File

@ -25,7 +25,6 @@ class WC_Admin_Duplicate_Product {
public function __construct() {
add_action( 'admin_action_duplicate_product', array( $this, 'duplicate_product_action' ) );
add_filter( 'post_row_actions', array( $this, 'dupe_link' ), 10, 2 );
add_filter( 'page_row_actions', array( $this, 'dupe_link' ), 10, 2 );
add_action( 'post_submitbox_start', array( $this, 'dupe_button' ) );
}
@ -69,9 +68,9 @@ class WC_Admin_Duplicate_Product {
}
if ( isset( $_GET['post'] ) ) {
$notifyUrl = wp_nonce_url( admin_url( "edit.php?post_type=product&action=duplicate_product&post=" . absint( $_GET['post'] ) ), 'woocommerce-duplicate-product_' . $_GET['post'] );
$notify_url = wp_nonce_url( admin_url( "edit.php?post_type=product&action=duplicate_product&post=" . absint( $_GET['post'] ) ), 'woocommerce-duplicate-product_' . $_GET['post'] );
?>
<div id="duplicate-action"><a class="submitduplicate duplication" href="<?php echo esc_url( $notifyUrl ); ?>"><?php _e( 'Copy to a new draft', 'woocommerce' ); ?></a></div>
<div id="duplicate-action"><a class="submitduplicate duplication" href="<?php echo esc_url( $notify_url ); ?>"><?php _e( 'Copy to a new draft', 'woocommerce' ); ?></a></div>
<?php
}
}
@ -237,7 +236,7 @@ class WC_Admin_Duplicate_Product {
global $wpdb;
$sql = $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", absint( $id ) );
$exclude = array_map( 'esc_sql', array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_meta', array( 'total_sales', '_wc_average_rating', '_wc_rating_count', '_wc_review_count' ) ) ) );
$exclude = array_map( 'esc_sql', array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_meta', array( 'total_sales', '_wc_average_rating', '_wc_rating_count', '_wc_review_count', '_sku' ) ) ) );
if ( sizeof( $exclude ) ) {
$sql .= " AND meta_key NOT IN ( '" . implode( "','", $exclude ) . "' )";

View File

@ -160,33 +160,25 @@ class WC_Admin_Help {
) );
}
$screen->add_help_tab( array(
'id' => 'woocommerce_docs_tab',
'title' => __( 'Documentation', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Documentation', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'Should you need help understanding, using, or extending WooCommerce, please read our documentation. You will find all kinds of resources including snippets, tutorials and much more.' , 'woocommerce' ) . '</p>' .
'<p><a href="' . 'http://docs.woothemes.com/documentation/plugins/woocommerce/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Docs&utm_campaign=Onboarding' . '" class="button button-primary">' . __( 'WooCommerce Documentation', 'woocommerce' ) . '</a> <a href="' . 'http://docs.woothemes.com/wc-apidocs/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=APIDocs&utm_campaign=Onboarding' . '" class="button">' . __( 'Developer API Docs', 'woocommerce' ) . '</a></p>'
) );
$screen->add_help_tab( array(
'id' => 'woocommerce_support_tab',
'title' => __( 'Support', 'woocommerce' ),
'title' => __( 'Help &amp; Support', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Support', 'woocommerce' ) . '</h2>' .
'<p>' . sprintf( __( 'After %sreading the documentation%s, for further assistance you can use the %scommunity forums%s on WordPress.org to talk with other users. If however you are a WooThemes customer, or need help with premium add-ons sold by WooThemes, please %suse our helpdesk%s.', 'woocommerce' ), '<a href="https://docs.woothemes.com/documentation/plugins/woocommerce/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Docs&utm_campaign=Onboarding">', '</a>', '<a href="https://wordpress.org/support/plugin/woocommerce">', '</a>', '<a href="https://www.woothemes.com/my-account/tickets/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Tickets&utm_campaign=Onboarding">', '</a>' ) . '</p>' .
'<h2>' . __( 'Help &amp; Support', 'woocommerce' ) . '</h2>' .
'<p>' . sprintf(
__( 'Should you need help understanding, using, or extending WooCommerce, %splease read our documentation%s. You will find all kinds of resources including snippets, tutorials and much more.' , 'woocommerce' ),
'<a href="http://docs.woothemes.com/documentation/plugins/woocommerce/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Docs&utm_campaign=Onboarding">',
'</a>'
) . '</p>' .
'<p>' . sprintf(
__( 'For further assistance with WooCommerce core you can use the %scommunity forum%s. If you need help with premium add-ons sold by WooThemes, please %suse our helpdesk%s.', 'woocommerce' ),
'<a href="https://wordpress.org/support/plugin/woocommerce">',
'</a>',
'<a href="https://www.woothemes.com/my-account/tickets/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Tickets&utm_campaign=Onboarding">',
'</a>'
) . '</p>' .
'<p>' . __( 'Before asking for help we recommend checking the system status page to identify any problems with your configuration.', 'woocommerce' ) . '</p>' .
'<p><a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button button-primary">' . __( 'System Status', 'woocommerce' ) . '</a> <a href="' . 'https://wordpress.org/support/plugin/woocommerce' . '" class="button">' . __( 'WordPress.org Forums', 'woocommerce' ) . '</a> <a href="' . 'http://www.woothemes.com/my-account/tickets/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Tickets&utm_campaign=Onboarding' . '" class="button">' . __( 'WooThemes Customer Support', 'woocommerce' ) . '</a></p>'
) );
$screen->add_help_tab( array(
'id' => 'woocommerce_education_tab',
'title' => __( 'Education', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Education', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'If you would like to learn about using WooCommerce from an expert, consider following a WooCommerce course ran by one of our educational partners.', 'woocommerce' ) . '</p>' .
'<p><a href="' . 'http://www.woothemes.com/educational-partners/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=EduPartners&utm_campaign=Onboarding' . '" class="button button-primary">' . __( 'View Education Partners', 'woocommerce' ) . '</a></p>'
'<p><a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button button-primary">' . __( 'System Status', 'woocommerce' ) . '</a> <a href="' . 'https://wordpress.org/support/plugin/woocommerce' . '" class="button">' . __( 'Community Forum', 'woocommerce' ) . '</a> <a href="' . 'http://www.woothemes.com/my-account/tickets/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Tickets&utm_campaign=Onboarding' . '" class="button">' . __( 'WooThemes Helpdesk', 'woocommerce' ) . '</a></p>'
) );
$screen->add_help_tab( array(
@ -199,6 +191,15 @@ class WC_Admin_Help {
) );
$screen->add_help_tab( array(
'id' => 'woocommerce_education_tab',
'title' => __( 'Education', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Education', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'If you would like to learn about using WooCommerce from an expert, consider following a WooCommerce course ran by one of our educational partners.', 'woocommerce' ) . '</p>' .
'<p><a href="' . 'http://www.woothemes.com/educational-partners/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=EduPartners&utm_campaign=Onboarding' . '" class="button button-primary">' . __( 'View Education Partners', 'woocommerce' ) . '</a></p>'
) );
$screen->add_help_tab( array(
'id' => 'woocommerce_onboard_tab',
'title' => __( 'Setup Wizard', 'woocommerce' ),

View File

@ -21,9 +21,10 @@ class WC_Admin_Notices {
* Array of notices - name => callback.
* @var array
*/
private $core_notices = array(
private static $core_notices = array(
'install' => 'install_notice',
'update' => 'update_notice',
'updating' => 'updating_notice',
'template_files' => 'template_file_check_notice',
'theme_support' => 'theme_check_notice',
'legacy_shipping' => 'legacy_shipping_notice',
@ -31,37 +32,61 @@ class WC_Admin_Notices {
'simplify_commerce' => 'simplify_commerce_notice',
);
/**
* Stores notices.
* @var array
*/
private static $notices = array();
/**
* Constructor.
*/
public function __construct() {
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
add_action( 'woocommerce_installed', array( $this, 'reset_admin_notices' ) );
add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
public static function init() {
self::$notices = get_option( 'woocommerce_admin_notices', array() );
add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) );
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
add_action( 'wp_loaded', array( __CLASS__, 'hide_notices' ) );
add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
if ( current_user_can( 'manage_woocommerce' ) ) {
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );
}
}
/**
* Store notices to DB
*/
public static function store_notices() {
update_option( 'woocommerce_admin_notices', self::get_notices() );
}
/**
* Get notices
* @return array
*/
public static function get_notices() {
return self::$notices;
}
/**
* Remove all notices.
*/
public static function remove_all_notices() {
delete_option( 'woocommerce_admin_notices' );
self::$notices = array();
}
/**
* Reset notices for themes when switched or a new version of WC is installed.
*/
public function reset_admin_notices() {
public static function reset_admin_notices() {
if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) {
self::add_notice( 'theme_support' );
}
$simplify_options = get_option( 'woocommerce_simplify_commerce_settings', array() );
if ( ! class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) && ! empty( $simplify_options['enabled'] ) && 'yes' === $simplify_options['enabled'] ) {
if ( ! class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) && ! empty( $simplify_options['enabled'] ) && 'yes' === $simplify_options['enabled'] && in_array( WC()->countries->get_base_country(), apply_filters( 'woocommerce_gateway_simplify_commerce_supported_countries', array( 'US', 'IE' ) ) ) ) {
WC_Admin_Notices::add_notice( 'simplify_commerce' );
}
@ -73,8 +98,7 @@ class WC_Admin_Notices {
* @param string $name
*/
public static function add_notice( $name ) {
$notices = array_unique( array_merge( get_option( 'woocommerce_admin_notices', array() ), array( $name ) ) );
update_option( 'woocommerce_admin_notices', $notices );
self::$notices = array_unique( array_merge( self::get_notices(), array( $name ) ) );
}
/**
@ -82,8 +106,7 @@ class WC_Admin_Notices {
* @param string $name
*/
public static function remove_notice( $name ) {
$notices = array_diff( get_option( 'woocommerce_admin_notices', array() ), array( $name ) );
update_option( 'woocommerce_admin_notices', $notices );
self::$notices = array_diff( self::get_notices(), array( $name ) );
delete_option( 'woocommerce_admin_notice_' . $name );
}
@ -93,13 +116,13 @@ class WC_Admin_Notices {
* @return boolean
*/
public static function has_notice( $name ) {
return in_array( $name, get_option( 'woocommerce_admin_notices', array() ) );
return in_array( $name, self::get_notices() );
}
/**
* Hide a notice if the GET variable is set.
*/
public function hide_notices() {
public static function hide_notices() {
if ( isset( $_GET['wc-hide-notice'] ) && isset( $_GET['_wc_notice_nonce'] ) ) {
if ( ! wp_verify_nonce( $_GET['_wc_notice_nonce'], 'woocommerce_hide_notices_nonce' ) ) {
wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
@ -118,16 +141,16 @@ class WC_Admin_Notices {
/**
* Add notices + styles if needed.
*/
public function add_notices() {
$notices = get_option( 'woocommerce_admin_notices', array() );
public static function add_notices() {
$notices = self::get_notices();
if ( $notices ) {
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
foreach ( $notices as $notice ) {
if ( ! empty( $this->core_notices[ $notice ] ) && apply_filters( 'woocommerce_show_admin_notice', true, $notice ) ) {
add_action( 'admin_notices', array( $this, $this->core_notices[ $notice ] ) );
if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'woocommerce_show_admin_notice', true, $notice ) ) {
add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
} else {
add_action( 'admin_notices', array( $this, 'output_custom_notices' ) );
add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
}
}
}
@ -146,11 +169,12 @@ class WC_Admin_Notices {
/**
* Output any stored custom notices.
*/
public function output_custom_notices() {
$notices = get_option( 'woocommerce_admin_notices', array() );
public static function output_custom_notices() {
$notices = self::get_notices();
if ( $notices ) {
foreach ( $notices as $notice ) {
if ( empty( $this->core_notices[ $notice ] ) ) {
if ( empty( self::$core_notices[ $notice ] ) ) {
$notice_html = get_option( 'woocommerce_admin_notice_' . $notice );
if ( $notice_html ) {
@ -164,21 +188,32 @@ class WC_Admin_Notices {
/**
* If we need to update, include a message with the update button.
*/
public function update_notice() {
public static function update_notice() {
include( 'views/html-notice-update.php' );
}
/**
* If we are updating, show progress.
*/
public static function updating_notice() {
if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
include( 'views/html-notice-updating.php' );
} else {
include( 'views/html-notice-updated.php' );
}
}
/**
* If we have just installed, show a message with the install pages button.
*/
public function install_notice() {
public static function install_notice() {
include( 'views/html-notice-install.php' );
}
/**
* Show the Theme Check notice.
*/
public function theme_check_notice() {
public static function theme_check_notice() {
if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( get_option( 'template' ), wc_get_core_supported_themes() ) ) {
include( 'views/html-notice-theme-support.php' );
} else {
@ -189,7 +224,7 @@ class WC_Admin_Notices {
/**
* Show a notice highlighting bad template files.
*/
public function template_file_check_notice() {
public static function template_file_check_notice() {
$core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' );
$outdated = false;
@ -227,7 +262,7 @@ class WC_Admin_Notices {
/**
* Show a notice asking users to convert to shipping zones.
*/
public function legacy_shipping_notice() {
public static function legacy_shipping_notice() {
$maybe_load_legacy_methods = array( 'flat_rate', 'free_shipping', 'international_delivery', 'local_delivery', 'local_pickup' );
$enabled = false;
@ -248,7 +283,7 @@ class WC_Admin_Notices {
/**
* No shipping methods.
*/
public function no_shipping_methods_notice() {
public static function no_shipping_methods_notice() {
if ( wc_shipping_enabled() && ( empty( $_GET['page'] ) || empty( $_GET['tab'] ) || 'wc-settings' !== $_GET['page'] || 'shipping' !== $_GET['tab'] ) ) {
global $wpdb;
@ -268,8 +303,8 @@ class WC_Admin_Notices {
/**
* Simplify Commerce is being removed from core.
*/
public function simplify_commerce_notice() {
if ( class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) ) {
public static function simplify_commerce_notice() {
if ( class_exists( 'WC_Gateway_Simplify_Commerce_Loader' ) || ! in_array( WC()->countries->get_base_country(), apply_filters( 'woocommerce_gateway_simplify_commerce_supported_countries', array( 'US', 'IE' ) ) ) ) {
self::remove_notice( 'simplify_commerce' );
return;
}
@ -279,4 +314,4 @@ class WC_Admin_Notices {
}
}
new WC_Admin_Notices();
WC_Admin_Notices::init();

View File

@ -526,11 +526,7 @@ class WC_Admin_Post_Types {
$usage_limit = esc_html( get_post_meta( $post->ID, 'usage_limit', true ) );
$usage_url = sprintf( '<a href="%s">%s</a>', admin_url( sprintf( 'edit.php?s=%s&post_status=all&post_type=shop_order', esc_html( $post->post_title ) ) ), $usage_count );
if ( $usage_limit ) {
printf( __( '%s / %s', 'woocommerce' ), $usage_url, $usage_limit );
} else {
printf( __( '%s / &infin;', 'woocommerce' ), $usage_url );
}
printf( _x( '%1$s / %2$s', 'Count / Limit', 'woocommerce' ), $usage_url, $usage_limit ? $usage_limit : '&infin;' );
break;
case 'expiry_date' :
$expiry_date = get_post_meta( $post->ID, 'expiry_date', true );
@ -2044,6 +2040,15 @@ class WC_Admin_Post_Types {
delete_transient( 'woocommerce_processing_order_count' );
wc_delete_shop_order_transients( $id );
} else if ( 'product' === $post_type ) {
// Check if SKU is valid before untrash the product.
$sku = get_post_meta( $id, '_sku', true );
if ( ! empty( $sku ) ) {
if ( ! wc_product_has_unique_sku( $id, $sku ) ) {
update_post_meta( $id, '_sku', '' );
}
}
}
}
}

View File

@ -566,7 +566,7 @@ class WC_Admin_Setup_Wizard {
'paypal-braintree' => array(
'name' => __( 'PayPal by Braintree', 'woocommerce' ),
'image' => WC()->plugin_url() . '/assets/images/paypal-braintree.png',
'description' => sprintf( __( 'Safe and secure payments using credit cards or your customer\'s paypal account. %sLearn more about PayPal%s.', 'woocommerce' ), '<a href="https://wordpress.org/plugins/woocommerce-gateway-paypal-powered-by-braintree/" target="_blank">', '</a>' ),
'description' => sprintf( __( 'Safe and secure payments using credit cards or your customer\'s PayPal account. %sLearn more about PayPal%s.', 'woocommerce' ), '<a href="https://wordpress.org/plugins/woocommerce-gateway-paypal-powered-by-braintree/" target="_blank">', '</a>' ),
'class' => 'featured featured-row-last',
'repo-slug' => 'woocommerce-gateway-paypal-powered-by-braintree',
),
@ -599,8 +599,8 @@ class WC_Admin_Setup_Wizard {
),
),
'cheque' => array(
'name' => __( 'Cheque Payments', 'woocommerce' ),
'description' => __( 'An simple offline gateway that lets you accept Cheque payment.', 'woocommerce' ),
'name' => _x( 'Check Payments', 'Check payment method', 'woocommerce' ),
'description' => __( 'An simple offline gateway that lets you accept a check as method of payment.', 'woocommerce' ),
'image' => '',
'class' => '',
),

View File

@ -125,11 +125,8 @@ class WC_Admin_Status {
$callback = $tools[ $action ]['callback'];
$return = call_user_func( $callback );
if ( $return === false ) {
if ( is_array( $callback ) ) {
echo '<div class="error inline"><p>' . sprintf( __( 'There was an error calling %s::%s', 'woocommerce' ), get_class( $callback[0] ), $callback[1] ) . '</p></div>';
} else {
echo '<div class="error inline"><p>' . sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback ) . '</p></div>';
}
$callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback;
echo '<div class="error inline"><p>' . sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ) . '</p></div>';
}
}
break;

View File

@ -80,7 +80,7 @@ class WC_Admin_Webhooks {
* @param WC_Webhook $webhook
*/
private function update_secret( $webhook ) {
$secret = ! empty( $_POST['webhook_secret'] ) ? $_POST['webhook_secret'] : get_user_meta( get_current_user_id(), 'woocommerce_api_consumer_secret', true );
$secret = ! empty( $_POST['webhook_secret'] ) ? $_POST['webhook_secret'] : wc_webhook_generate_secret();
$webhook->set_secret( $secret );
}

View File

@ -24,6 +24,7 @@ class WC_Admin {
public function __construct() {
add_action( 'init', array( $this, 'includes' ) );
add_action( 'current_screen', array( $this, 'conditional_includes' ) );
add_action( 'admin_init', array( $this, 'buffer' ), 1 );
add_action( 'admin_init', array( $this, 'preview_emails' ) );
add_action( 'admin_init', array( $this, 'prevent_admin_access' ) );
add_action( 'admin_init', array( $this, 'admin_redirects' ) );
@ -31,6 +32,13 @@ class WC_Admin {
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
}
/**
* Output buffering allows admin screens to make redirects later on.
*/
public function buffer() {
ob_start();
}
/**
* Include any classes we need within admin.
*/
@ -93,24 +101,38 @@ class WC_Admin {
/**
* Handle redirects to setup/welcome page after install and updates.
*
* Transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters.
* For setup wizard, transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters.
*/
public function admin_redirects() {
if ( ! get_transient( '_wc_activation_redirect' ) ) {
return;
}
// Nonced plugin install redirects (whitelisted)
if ( ! empty( $_GET['wc-install-plugin-redirect'] ) ) {
$plugin_slug = wc_clean( $_GET['wc-install-plugin-redirect'] );
delete_transient( '_wc_activation_redirect' );
if ( current_user_can( 'install_plugins' ) && in_array( $plugin_slug, array( 'woocommerce-gateway-stripe' ) ) ) {
$nonce = wp_create_nonce( 'install-plugin_' . $plugin_slug );
$url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug . '&_wpnonce=' . $nonce );
} else {
$url = admin_url( 'plugin-install.php?tab=search&type=term&s=' . $plugin_slug );
}
if ( ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'wc-setup' ) ) ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_woocommerce' ) || apply_filters( 'woocommerce_prevent_automatic_wizard_redirect', false ) ) {
return;
}
// If the user needs to install, send them to the setup wizard
if ( WC_Admin_Notices::has_notice( 'install' ) ) {
wp_safe_redirect( admin_url( 'index.php?page=wc-setup' ) );
wp_safe_redirect( $url );
exit;
}
// Setup wizard redirect
if ( get_transient( '_wc_activation_redirect' ) ) {
delete_transient( '_wc_activation_redirect' );
if ( ( ! empty( $_GET['page'] ) && in_array( $_GET['page'], array( 'wc-setup' ) ) ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_woocommerce' ) || apply_filters( 'woocommerce_prevent_automatic_wizard_redirect', false ) ) {
return;
}
// If the user needs to install, send them to the setup wizard
if ( WC_Admin_Notices::has_notice( 'install' ) ) {
wp_safe_redirect( admin_url( 'index.php?page=wc-setup' ) );
exit;
}
}
}
/**

View File

@ -49,7 +49,7 @@ class WC_Meta_Box_Order_Actions {
if ( ! empty( $mails ) ) {
foreach ( $mails as $mail ) {
if ( in_array( $mail->id, $available_emails ) && 'yes' === $mail->enabled ) {
if ( in_array( $mail->id, $available_emails ) && 'no' !== $mail->enabled ) {
echo '<option value="send_email_'. esc_attr( $mail->id ) .'">' . esc_html( $mail->title ) . '</option>';
}
}
@ -57,7 +57,7 @@ class WC_Meta_Box_Order_Actions {
?>
</optgroup>
<option value="regenerate_download_permissions"><?php _e( 'Generate download permissions', 'woocommerce' ); ?></option>
<option value="regenerate_download_permissions"><?php _e( 'Regenerate download permissions', 'woocommerce' ); ?></option>
<?php foreach( apply_filters( 'woocommerce_order_actions', array() ) as $action => $title ) { ?>
<option value="<?php echo $action; ?>"><?php echo $title; ?></option>
@ -97,6 +97,7 @@ class WC_Meta_Box_Order_Actions {
* @param WP_Post $post
*/
public static function save( $post_id, $post ) {
global $wpdb;
// Order data saved, now get it so we can manipulate status
$order = wc_get_order( $post_id );
@ -135,9 +136,14 @@ class WC_Meta_Box_Order_Actions {
// Change the post saved message
add_filter( 'redirect_post_location', array( __CLASS__, 'set_email_sent_message' ) );
} elseif ( $action == 'regenerate_download_permissions' ) {
} elseif ( 'regenerate_download_permissions' === $action ) {
delete_post_meta( $post_id, '_download_permissions_granted' );
$wpdb->delete(
$wpdb->prefix . 'woocommerce_downloadable_product_permissions',
array( 'order_id' => $post_id ),
array( '%d' )
);
wc_downloadable_product_permissions( $post_id );
} else {

View File

@ -179,6 +179,11 @@ class WC_Meta_Box_Order_Data {
echo ' (' . esc_html( $transaction_id ) . ')';
}
}
if ( $paid_date = $order->paid_date ) {
printf( ' ' . _x( 'on %s @ %s', 'on date at time', 'woocommerce' ), date_i18n( get_option( 'date_format' ), strtotime( $order->paid_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $order->paid_date ) ) );
}
echo '. ';
}

View File

@ -462,7 +462,7 @@ class WC_Meta_Box_Product_Data {
$metabox_class[] = $taxonomy;
$attribute_label = wc_attribute_label( $taxonomy );
} else {
$attribute_label = apply_filters( 'woocommerce_attribute_label', $attribute['name'], $attribute['name'] );
$attribute_label = apply_filters( 'woocommerce_attribute_label', $attribute['name'], $attribute['name'], false );
}
include( 'views/html-product-attribute.php' );

View File

@ -10,7 +10,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<button type="button" rel="<?php echo absint( $download->product_id ) . ',' . esc_attr( $download->download_id ); ?>" class="revoke_access button"><?php _e( 'Revoke Access', 'woocommerce' ); ?></button>
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'woocommerce' ); ?>"></div>
<strong>
<?php echo '#' . absint( $product->id ) . ' &mdash; ' . apply_filters( 'woocommerce_admin_download_permissions_title', $product->get_title(), $download->product_id, $download->order_id, $download->order_key, $download->download_id ) . ' &mdash; ' . sprintf( __( '%s: %s', 'woocommerce' ), $file_count, wc_get_filename_from_url( $product->get_file_download_path( $download->download_id ) ) ) . ' &mdash; ' . sprintf( _n('Downloaded %s time', 'Downloaded %s times', absint( $download->download_count ), 'woocommerce'), absint( $download->download_count ) ); ?>
<?php echo '#' . absint( $product->id ) . ' &mdash; ' . apply_filters( 'woocommerce_admin_download_permissions_title', $product->get_title(), $download->product_id, $download->order_id, $download->order_key, $download->download_id ) . ' &mdash; ' . esc_html( $file_count ) . ': ' . wc_get_filename_from_url( $product->get_file_download_path( $download->download_id ) ) . ' &mdash; ' . sprintf( _n( 'Downloaded %s time', 'Downloaded %s times', absint( $download->download_count ), 'woocommerce'), absint( $download->download_count ) ); ?>
</strong>
</h3>
<table cellpadding="0" cellspacing="0" class="wc-metabox-content">
@ -26,6 +26,19 @@ if ( ! defined( 'ABSPATH' ) ) {
<label><?php _e( 'Access expires', 'woocommerce' ); ?></label>
<input type="text" class="short date-picker" name="access_expires[<?php echo $loop; ?>]" value="<?php echo $download->access_expires > 0 ? date_i18n( 'Y-m-d', strtotime( $download->access_expires ) ) : ''; ?>" maxlength="10" placeholder="<?php esc_attr_e( 'Never', 'woocommerce' ); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
</td>
<td>
<label><?php _e( 'Customer download link', 'woocommerce' ); ?></label>
<?php
$download_link = add_query_arg( array(
'download_file' => $download->product_id,
'order' => $download->order_key,
'email' => urlencode( $download->user_email ),
'key' => $download->download_id
), trailingslashit( home_url() ) );
echo '<a href="' . esc_url( $download_link ) . '">' . esc_html( $file_count ) . '</a>';
?>
</td>
</tr>
</tbody>
</table>

View File

@ -33,7 +33,7 @@
$meta['meta_key'] = wc_attribute_label( wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
$meta['meta_value'] = isset( $term->name ) ? $term->name : $meta['meta_value'];
} else {
$meta['meta_key'] = apply_filters( 'woocommerce_attribute_label', wc_attribute_label( $meta['meta_key'], $_product ), $meta['meta_key'] );
$meta['meta_key'] = wc_attribute_label( $meta['meta_key'], $_product );
}
echo '<tr><th>' . wp_kses_post( rawurldecode( $meta['meta_key'] ) ) . ':</th><td>' . wp_kses_post( wpautop( make_clickable( rawurldecode( $meta['meta_value'] ) ) ) ) . '</td></tr>';

View File

@ -220,7 +220,7 @@ if ( wc_tax_enabled() ) {
<?php if ( $order->is_editable() ) : ?>
<button type="button" class="button add-line-item"><?php _e( 'Add item(s)', 'woocommerce' ); ?></button>
<?php else : ?>
<span class="description tips" data-tip="<?php esc_attr_e( 'To edit this order change the status back to "Pending"', 'woocommerce' ); ?>"><?php _e( 'This order has been paid for and is no longer editable', 'woocommerce' ); ?></span>
<span class="description"><?php echo wc_help_tip( __( 'To edit this order change the status back to "Pending"', 'woocommerce' ) ); ?> <?php _e( 'This order is no longer editable.', 'woocommerce' ); ?></span>
<?php endif; ?>
<?php if ( wc_tax_enabled() && $order->is_editable() ) : ?>
<button type="button" class="button add-order-tax"><?php _e( 'Add tax', 'woocommerce' ); ?></button>
@ -272,7 +272,7 @@ if ( wc_tax_enabled() ) {
</td>
</tr>
<tr>
<td class="label"><label for="refund_reason"><?php _e( 'Reason for refund (optional)', 'woocommerce' ); ?>:</label></td>
<td class="label"><label for="refund_reason"><?php echo wc_help_tip( __( 'Note: the refund reason will be visible by the customer.', 'woocommerce' ) ); ?> <?php _e( 'Reason for refund (optional)', 'woocommerce' ); ?>:</label></td>
<td class="total">
<input type="text" class="text" id="refund_reason" name="refund_reason" />
<div class="clear"></div>

View File

@ -55,6 +55,58 @@ class WC_Settings_Accounts extends WC_Settings_Page {
array( 'type' => 'sectionend', 'id' => 'account_page_options' ),
array( 'title' => '', 'type' => 'title', 'id' => 'account_registration_options' ),
array(
'title' => __( 'Enable Registration', 'woocommerce' ),
'desc' => __( 'Enable registration on the "Checkout" page', 'woocommerce' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Enable registration on the "My Account" page', 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array(
'title' => __( 'Login', 'woocommerce' ),
'desc' => __( 'Display returning customer login reminder on the "Checkout" page', 'woocommerce' ),
'id' => 'woocommerce_enable_checkout_login_reminder',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'title' => __( 'Account Creation', 'woocommerce' ),
'desc' => __( 'Automatically generate username from customer email', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Automatically generate customer password', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_password',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'account_registration_options'),
array( 'title' => __( 'My Account Endpoints', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique.', 'woocommerce' ), 'id' => 'account_endpoint_options' ),
array(
@ -131,57 +183,6 @@ class WC_Settings_Accounts extends WC_Settings_Page {
array( 'type' => 'sectionend', 'id' => 'account_endpoint_options' ),
array( 'title' => __( 'Registration Options', 'woocommerce' ), 'type' => 'title', 'id' => 'account_registration_options' ),
array(
'title' => __( 'Enable Registration', 'woocommerce' ),
'desc' => __( 'Enable registration on the "Checkout" page', 'woocommerce' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Enable registration on the "My Account" page', 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array(
'desc' => __( 'Display returning customer login reminder on the "Checkout" page', 'woocommerce' ),
'id' => 'woocommerce_enable_checkout_login_reminder',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'title' => __( 'Account Creation', 'woocommerce' ),
'desc' => __( 'Automatically generate username from customer email', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Automatically generate customer password', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_password',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'account_registration_options'),
) );
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );

View File

@ -69,11 +69,21 @@ class WC_Settings_General extends WC_Settings_Page {
'css' => 'min-width: 350px;',
'desc_tip' => true,
'options' => array(
'all' => __( 'Sell to all countries', 'woocommerce' ),
'specific' => __( 'Sell to specific countries only', 'woocommerce' )
'all' => __( 'Sell to All Countries', 'woocommerce' ),
'all_except' => __( 'Sell to All Countries, Except For&hellip;', 'woocommerce' ),
'specific' => __( 'Sell to Specific Countries', 'woocommerce' )
)
),
array(
'title' => __( 'Sell to All Countries, Except For&hellip;', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_all_except_countries',
'css' => 'min-width: 350px;',
'default' => '',
'type' => 'multi_select_countries'
),
array(
'title' => __( 'Sell to Specific Countries', 'woocommerce' ),
'desc' => '',

View File

@ -127,7 +127,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
// Load shipping methods so we can show any global options they may have
$shipping_methods = WC()->shipping->load_shipping_methods();
if ( '' == $current_section ) {
if ( '' === $current_section ) {
$this->output_zones_screen();
} elseif ( 'options' === $current_section ) {
$settings = $this->get_settings();
@ -224,12 +224,15 @@ class WC_Settings_Shipping extends WC_Settings_Page {
* Show zones
*/
protected function zones_screen() {
global $wpdb;
$allowed_countries = WC()->countries->get_allowed_countries();
$continents = WC()->countries->get_continents();
$continents = WC()->countries->get_continents();
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods" ) );
wp_localize_script( 'wc-shipping-zones', 'shippingZonesLocalizeScript', array(
'zones' => WC_Shipping_Zones::get_zones(),
'default_zone' => array(
'zones' => WC_Shipping_Zones::get_zones(),
'default_zone' => array(
'zone_id' => 0,
'zone_name' => '',
'zone_order' => null,
@ -238,6 +241,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
'default_zone_name' => __( 'Zone', 'woocommerce' ),
),
) );
wp_enqueue_script( 'wc-shipping-zones' );
@ -282,8 +286,8 @@ class WC_Settings_Shipping extends WC_Settings_Page {
protected function output_shipping_class_screen() {
$wc_shipping = WC_Shipping::instance();
wp_localize_script( 'wc-shipping-classes', 'shippingClassesLocalizeScript', array(
'classes' => $wc_shipping->get_shipping_classes(),
'default_shipping_class' => array(
'classes' => $wc_shipping->get_shipping_classes(),
'default_shipping_class' => array(
'term_id' => 0,
'name' => '',
'description' => '',

View File

@ -4,56 +4,63 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<h2><?php _e( 'Shipping Classes', 'woocommerce' ); ?></h2>
<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>
<h2>
<?php _e( 'Shipping Classes', 'woocommerce' ); ?>
<?php echo wc_help_tip( __( 'Shipping classes can be used to group products of similar type and can be used by some Shipping Methods (such as Flat Rate Shipping) to provide different rates to different classes of product.', 'woocommerce' ) ); ?>
</h2>
<table class="wc-shipping-classes widefat">
<thead>
<tr>
<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-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-actions">&nbsp;</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<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>
</tr>
</tfoot>
<tbody class="wc-shipping-class-rows"></tbody>
<thead>
<tr>
<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-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
<th class="wc-shipping-class-count"><?php esc_html_e( 'Product Count', 'woocommerce' ); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4">
<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>
</td>
</tr>
</tfoot>
<tbody class="wc-shipping-class-rows"></tbody>
</table>
<script type="text/html" id="tmpl-wc-shipping-class-row-blank">
<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>
</script>
<script type="text/html" id="tmpl-wc-shipping-class-row">
<tr data-id="{{ data.term_id }}">
<td class="wc-shipping-class-name">
<div class="view">{{ data.name }}</div>
<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>
</td>
<td class="wc-shipping-class-slug">
<div class="view">{{ data.slug }}</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>
</td>
<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>
<tr data-id="{{ data.term_id }}">
<td class="wc-shipping-class-name">
<div class="view">
{{ data.name }}
<div class="row-actions">
<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>
</div>
<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 class="row-actions">
<a class="wc-shipping-class-cancel-edit" href="#"><?php _e( 'Cancel changes', 'woocommerce' ); ?></a>
</div>
</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>
<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 class="wc-shipping-class-slug">
<div class="view">{{ data.slug }}</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>
</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>

View File

@ -4,45 +4,36 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<h2><?php _e( 'Shipping Methods', 'woocommerce' ); ?> (<?php echo esc_html( $zone->get_zone_name() ); ?>) <?php echo wc_back_link( __( 'Return to Shipping Zones', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?></h2>
<p><?php _e( 'The following shipping methods apply to customers with shipping addresses within this zone.', 'woocommerce' ); ?><p>
<h2>
<a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=shipping' ); ?>"><?php _e( 'Shipping Zones', 'woocommerce' ); ?></a> &gt;
<?php echo esc_html( $zone->get_zone_name() ); ?>
<?php echo wc_help_tip( __( 'The following shipping methods apply to customers with shipping addresses within this zone.', 'woocommerce' ) ); ?>
</h2>
<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>
<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-enabled"><?php esc_html_e( 'Enabled', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-actions">&nbsp;</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="6">
<div class="wc-shipping-zone-method-selector">
<select name="add_method_id">
<?php
foreach ( $shipping_methods as $method ) {
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
echo '<option value="' . esc_attr( $method->id ) . '">' . esc_attr( $method->title ) . '</option>';
}
?>
</select>
<input type="submit" class="button wc-shipping-zone-add-method" value="<?php esc_attr_e( 'Add shipping method', 'woocommerce' ); ?>" />
</div>
<input type="submit" name="save" class="button button-primary wc-shipping-zone-method-save" value="<?php esc_attr_e( 'Save shipping methods', 'woocommerce' ); ?>" disabled />
</td>
</tr>
</tfoot>
<tbody class="wc-shipping-zone-method-rows"></tbody>
<th class="wc-shipping-zone-method-type"><?php esc_html_e( 'Type', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-description"><?php esc_html_e( 'Description', 'woocommerce' ); ?></th>
</tr>
</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>
</tr>
</tfoot>
<tbody class="wc-shipping-zone-method-rows"></tbody>
</table>
<script type="text/html" id="tmpl-wc-shipping-zone-method-row-blank">
<tr>
<td class="wc-shipping-zone-method-blank-state" colspan="6">
<td class="wc-shipping-zone-method-blank-state" colspan="5">
<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( 'Choose a method from the dropdown below and click "Add shipping method" to get started.', 'woocommerce' ); ?></p>
@ -51,16 +42,18 @@ if ( ! defined( 'ABSPATH' ) ) {
</script>
<script type="text/html" id="tmpl-wc-shipping-zone-method-row">
<tr data-id="{{ data.instance_id }}" data-enabled="{{ data.enabled }}">
<td width="1%" class="wc-shipping-zone-method-sort"></td>
<td class="wc-shipping-zone-method-title"><a href="admin.php?page=wc-settings&amp;tab=shipping&amp;instance_id={{ data.instance_id }}">{{ data.title }}</a></td>
<td class="wc-shipping-zone-method-type">{{ data.method_title }}</td>
<td 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-actions">
<a class="wc-shipping-zone-method-delete tips" data-tip="<?php esc_attr_e( 'Delete', 'woocommerce' ); ?>" href="#"><?php _e( 'Delete', 'woocommerce' ); ?></a><a class="wc-shipping-zone-method-settings tips" data-tip="<?php esc_attr_e( 'Settings', 'woocommerce' ); ?>" href="admin.php?page=wc-settings&amp;tab=shipping&amp;instance_id={{ data.instance_id }}"><?php _e( 'Settings', 'woocommerce' ); ?></a>
<tr data-id="{{ data.instance_id }}" data-enabled="{{ data.enabled }}">
<td width="1%" class="wc-shipping-zone-method-sort"></td>
<td class="wc-shipping-zone-method-title">
<a class="wc-shipping-zone-method-settings" href="admin.php?page=wc-settings&amp;tab=shipping&amp;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&amp;tab=shipping&amp;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>
</tr>
<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-description">{{ data.method_description }}</td>
</tr>
</script>
<script type="text/template" id="tmpl-wc-modal-shipping-method-settings">
@ -68,7 +61,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="wc-backbone-modal-content">
<section class="wc-backbone-modal-main" role="main">
<header class="wc-backbone-modal-header">
<h1><?php echo esc_html( sprintf( __( '%s Settings', 'Shipping Method Settings', 'woocommerce' ), '{{{ data.method.method_title }}}' ) ); ?></h1>
<h1><?php echo esc_html( sprintf( _x( '%s Settings', 'Shipping Method Settings', 'woocommerce' ), '{{{ data.method.method_title }}}' ) ); ?></h1>
<button class="modal-close modal-close-link dashicons dashicons-no-alt">
<span class="screen-reader-text"><?php _e( 'Close modal panel', 'woocommerce' ); ?></span>
</button>
@ -89,3 +82,40 @@ if ( ! defined( 'ABSPATH' ) ) {
</div>
<div class="wc-backbone-modal-backdrop modal-close"></div>
</script>
<script type="text/template" id="tmpl-wc-modal-add-shipping-method">
<div class="wc-backbone-modal">
<div class="wc-backbone-modal-content">
<section class="wc-backbone-modal-main" role="main">
<header class="wc-backbone-modal-header">
<h1><?php _e( 'Add shipping method', 'woocommerce' ); ?></h1>
<button class="modal-close modal-close-link dashicons dashicons-no-alt">
<span class="screen-reader-text"><?php _e( 'Close modal panel', 'woocommerce' ); ?></span>
</button>
</header>
<article>
<form action="" method="post">
<div class="wc-shipping-zone-method-selector">
<select name="add_method_id">
<?php
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
echo '<option data-description="' . esc_attr( $method->method_description ) . '" value="' . esc_attr( $method->id ) . '">' . esc_attr( $method->title ) . '</li>';
}
?>
</select>
</div>
</form>
</article>
<footer>
<div class="inner">
<button id="btn-ok" class="button button-primary button-large"><?php _e( 'Add shipping method', 'woocommerce' ); ?></button>
</div>
</footer>
</section>
</div>
</div>
<div class="wc-backbone-modal-backdrop modal-close"></div>
</script>

View File

@ -3,5 +3,10 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<h2><?php echo esc_html( $shipping_method->get_method_title() ); ?> <?php wc_back_link( __( 'Return to Shipping Methods', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=' . absint( $zone->get_zone_id() ) ) ); ?></h2>
<h2>
<a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=shipping' ); ?>"><?php _e( 'Shipping Zones', 'woocommerce' ); ?></a> &gt;
<a href="<?php echo admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=' . absint( $zone->get_zone_id() ) ); ?>"><?php echo esc_html( $zone->get_zone_name() ); ?></a> &gt;
<?php echo esc_html( $shipping_method->get_method_title() ); ?>
</h2>
<?php $shipping_method->admin_options(); ?>

View File

@ -4,38 +4,40 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<h2><?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&lsquo;s shipping address and present the shipping methods within that zone to them.', 'woocommerce' ) ); ?></h2>
<h2>
<?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&lsquo;s shipping address and present the shipping methods within that zone to them.', 'woocommerce' ) ); ?>
</h2>
<table class="wc-shipping-zones widefat">
<thead>
<tr>
<th class="wc-shipping-zone-sort"><?php echo wc_help_tip( __( 'Drag and drop to re-order your custom zones. This is the order in which they will be matched against the customer address.', '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-methods"><?php esc_html_e( 'Shipping Method(s)', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-actions">&nbsp;</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<a class="button button-secondary wc-shipping-zone-add" href="#"><?php esc_html_e( 'Add shipping zone', 'woocommerce' ); ?></a>
<input type="submit" name="save" class="button button-primary wc-shipping-zone-save" value="<?php esc_attr_e( 'Save shipping zones', 'woocommerce' ); ?>" disabled />
</td>
</tr>
</tfoot>
<tbody class="wc-shipping-zone-rows"></tbody>
<tbody>
<tr data-id="0">
<td width="1%" class="wc-shipping-zone-worldwide"></td>
<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>
<div class="row-actions">
<a href="admin.php?page=wc-settings&amp;tab=shipping&amp;zone_id={{ data.zone_id }}"><?php _e( 'Edit shipping methods', 'woocommerce' ); ?></a>
</div>
</td>
<td class="wc-shipping-zone-region"><?php esc_html_e( 'Shipping Methods added here will apply to shipping addresses that aren&lsquo;t included in any other shipping zone.', 'woocommerce' ); ?></td>
<td class="wc-shipping-zone-methods">
<thead>
<tr>
<th class="wc-shipping-zone-sort"><?php echo wc_help_tip( __( 'Drag and drop to re-order your custom zones. This is the order in which they will be matched against the customer address.', '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-methods"><?php esc_html_e( 'Shipping Method(s)', 'woocommerce' ); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4">
<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>
</tr>
</tfoot>
<tbody class="wc-shipping-zone-rows"></tbody>
<tbody>
<tr data-id="0">
<td width="1%" class="wc-shipping-zone-worldwide"></td>
<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>
<div class="row-actions">
<a href="admin.php?page=wc-settings&amp;tab=shipping&amp;zone_id={{ data.zone_id }}"><?php _e( 'View', 'woocommerce' ); ?></a>
</div>
</td>
<td class="wc-shipping-zone-region"><?php esc_html_e( 'Shipping Methods added here will apply to shipping addresses that aren&lsquo;t included in any other shipping zone.', 'woocommerce' ); ?></td>
<td class="wc-shipping-zone-methods">
<ul>
<?php
$worldwide = new WC_Shipping_Zone( 0 );
@ -43,47 +45,55 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( $methods ) {
foreach ( $methods as $method ) {
$class_name = 'yes' === $method->enabled ? 'method_enabled' : 'method_disabled';
$class_name = 'yes' === $method->enabled ? 'method_enabled' : 'method_disabled';
echo '<li class="wc-shipping-zone-method"><a href="admin.php?page=wc-settings&amp;tab=shipping&amp;instance_id=' . absint( $method->instance_id ) . '" class="' . esc_attr( $class_name ) . '">' . esc_html( $method->get_title() ) . '</a></li>';
}
} else {
echo '<li class="wc-shipping-zone-method">&ndash;</li>';
}
?>
<li class="wc-shipping-zone-methods-add-row"><a href="#" class="add_shipping_method button" data-tip="<?php esc_attr_e( 'Save changes to continue adding shipping methods to this zone.', 'woocommerce' ); ?>"><?php _e( 'Add shipping method', 'woocommerce' ); ?></a></li>
<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>
</td>
<td class="wc-shipping-zone-actions"></td>
</tr>
</tbody>
</tr>
</tbody>
</table>
<script type="text/html" id="tmpl-wc-shipping-zone-row-blank">
<tr>
<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><?php _e( 'For example:', 'woocommerce' ); ?></p>
<ul>
<li><?php _e( 'Local Zone = California ZIP 90210 = Local pickup', 'woocommerce' ); ?>
<li><?php _e( 'US Domestic Zone = All US states = Flat rate shipping', 'woocommerce' ); ?>
<li><?php _e( 'Europe Zone = Any country in Europe = Flat rate shipping', 'woocommerce' ); ?>
</ul>
<p><?php _e( 'Add as many zones as you need &ndash; customers will only see the methods available for their address.', 'woocommerce' ); ?></p>
<a class="button button-primary wc-shipping-zone-add"><?php _e( 'Add shipping zone', 'woocommerce' ); ?></a>
</td>
</tr>
<?php if ( 0 === $method_count ) : ?>
<tr>
<td class="wc-shipping-zones-blank-state" colspan="4">
<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>
<ul>
<li><?php _e( 'Local Zone = California ZIP 90210 = Local pickup', 'woocommerce' ); ?>
<li><?php _e( 'US Domestic Zone = All US states = Flat rate shipping', 'woocommerce' ); ?>
<li><?php _e( 'Europe Zone = Any country in Europe = Flat rate shipping', 'woocommerce' ); ?>
</ul>
<p><?php _e( 'Add as many zones as you need &ndash; customers will only see the methods available for their address.', 'woocommerce' ); ?></p>
<a class="button button-primary wc-shipping-zone-add"><?php _e( 'Add shipping zone', 'woocommerce' ); ?></a>
</td>
</tr>
<?php endif; ?>
</script>
<script type="text/html" id="tmpl-wc-shipping-zone-row">
<tr data-id="{{ data.zone_id }}">
<td width="1%" class="wc-shipping-zone-sort"></td>
<td class="wc-shipping-zone-name">
<div class="view">
<a href="admin.php?page=wc-settings&amp;tab=shipping&amp;zone_id={{ data.zone_id }}">{{ data.zone_name }}</a>
<div class="row-actions">
<a class="wc-shipping-zone-edit" href="#"><?php _e( 'Edit Zone', 'woocommerce' ); ?></a> | <a href="admin.php?page=wc-settings&amp;tab=shipping&amp;zone_id={{ data.zone_id }}"><?php _e( 'Edit shipping methods', '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>
</td>
<tr data-id="{{ data.zone_id }}">
<td width="1%" class="wc-shipping-zone-sort"></td>
<td class="wc-shipping-zone-name">
<div class="view">
<a href="admin.php?page=wc-settings&amp;tab=shipping&amp;zone_id={{ data.zone_id }}">{{ data.zone_name }}</a>
<div class="row-actions">
<a href="admin.php?page=wc-settings&amp;tab=shipping&amp;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 class="wc-shipping-zone-region">
<div class="view">{{ data.formatted_zone_location }}</div>
<div class="edit">
@ -109,21 +119,18 @@ if ( ! defined( 'ABSPATH' ) ) {
<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( 'Wildcards and numerical ranges are supported too, for example, 90210-99000 and CB23*', 'woocommerce' ) ?></span>
<span class="description"><?php _e( 'Postcodes containing wildcards (e.g. CB23*) and fully numeric ranges (e.g. 90210-99000) are also supported.', 'woocommerce' ) ?></span>
</div>
</div>
</td>
<td class="wc-shipping-zone-methods">
<td class="wc-shipping-zone-methods">
<div>
<ul>
<li class="wc-shipping-zone-methods-add-row"><a href="#" class="add_shipping_method button" data-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>
<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>
</div>
</td>
<td class="wc-shipping-zone-actions">
<a class="wc-shipping-zone-delete tips" data-tip="<?php _e( 'Delete', 'woocommerce' ); ?>" href="#"><?php _e( 'Delete', 'woocommerce' ); ?></a>
</td>
</tr>
</tr>
</script>
<script type="text/template" id="tmpl-wc-modal-add-shipping-method">
@ -138,19 +145,19 @@ if ( ! defined( 'ABSPATH' ) ) {
</header>
<article>
<form action="" method="post">
<div class="wc-shipping-zone-method-selector">
<select name="add_method_id">
<?php
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
echo '<option data-description="' . esc_attr( $method->method_description ) . '" value="' . esc_attr( $method->id ) . '">' . esc_attr( $method->title ) . '</li>';
}
?>
</select>
<input type="hidden" name="zone_id" value="{{{ data.zone_id }}}" />
</div>
<div class="wc-shipping-zone-method-selector">
<select name="add_method_id">
<?php
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
echo '<option data-description="' . esc_attr( $method->method_description ) . '" value="' . esc_attr( $method->id ) . '">' . esc_attr( $method->title ) . '</li>';
}
?>
</select>
<input type="hidden" name="zone_id" value="{{{ data.zone_id }}}" />
</div>
</form>
</article>
<footer>

View File

@ -10,12 +10,14 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<div class="wrap woocommerce">
<div class="icon32 icon32-woocommerce-reports" id="icon-woocommerce"><br /></div>
<h1><?php echo sprintf( esc_html__( '%s Report' ), $reports[ $current_tab ]['title'] ); ?></h1>
<h1><?php echo sprintf( esc_html__( '%s Report', 'woocommerce' ), $reports[ $current_tab ]['title'] ); ?></h1>
<h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php
foreach ( $reports as $key => $report_group ) {
echo '<a href="'.admin_url( 'admin.php?page=wc-reports&tab=' . urlencode( $key ) ).'" class="nav-tab ';
if ( $current_tab == $key ) echo 'nav-tab-active';
echo '<a href="' . admin_url( 'admin.php?page=wc-reports&tab=' . urlencode( $key ) ) . '" class="nav-tab ';
if ( $current_tab == $key ) {
echo 'nav-tab-active';
}
echo '">' . esc_html( $report_group[ 'title' ] ) . '</a>';
}
@ -33,7 +35,9 @@ if ( ! defined( 'ABSPATH' ) ) {
$link = '<a href="admin.php?page=wc-reports&tab=' . urlencode( $current_tab ) . '&amp;report=' . urlencode( $key ) . '" class="';
if ( $key == $current_report ) $link .= 'current';
if ( $key == $current_report ) {
$link .= 'current';
}
$link .= '">' . $report['title'] . '</a>';
@ -41,7 +45,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
echo implode(' | </li><li>', $links);
echo implode( ' | </li><li>', $links );
?></li>
</ul>
@ -59,11 +63,13 @@ if ( ! defined( 'ABSPATH' ) ) {
echo '<h2 class="screen-reader-text">' . esc_html( $report['title'] ) . '</h2>';
}
if ( $report['description'] )
if ( $report['description'] ) {
echo '<p>' . $report['description'] . '</p>';
}
if ( $report['callback'] && ( is_callable( $report['callback'] ) ) )
if ( $report['callback'] && ( is_callable( $report['callback'] ) ) ) {
call_user_func( $report['callback'], $current_report );
}
}
?>
</div>

View File

@ -6,6 +6,7 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $wpdb;
?>
<div class="updated woocommerce-message inline">
@ -172,23 +173,24 @@ if ( ! defined( 'ABSPATH' ) ) {
<td><?php echo extension_loaded( 'suhosin' ) ? '<span class="dashicons dashicons-yes"></span>' : '&ndash;'; ?></td>
</tr>
<?php endif; ?>
<tr>
<td data-export-label="MySQL Version"><?php _e( 'MySQL Version', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'The version of MySQL installed on your hosting server.', 'woocommerce' ) ); ?></td>
<td>
<?php
/** @global wpdb $wpdb */
global $wpdb;
$mysql_version = $wpdb->db_version();
<?php
if ( ! empty( $wpdb->is_mysql ) ) : ?>
<tr>
<td data-export-label="MySQL Version"><?php _e( 'MySQL Version', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'The version of MySQL installed on your hosting server.', 'woocommerce' ) ); ?></td>
<td>
<?php
$mysql_version = $wpdb->db_version();
if ( version_compare( $mysql_version, '5.6', '<' ) ) {
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%s - We recommend a minimum MySQL version of 5.6. See: %s', 'woocommerce' ), esc_html( $mysql_version ), '<a href="https://wordpress.org/about/requirements/" target="_blank">' . __( 'WordPress Requirements', 'woocommerce' ) . '</a>' ) . '</mark>';
} else {
echo '<mark class="yes">' . esc_html( $mysql_version ) . '</mark>';
}
?>
</td>
</tr>
if ( version_compare( $mysql_version, '5.6', '<' ) ) {
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%s - We recommend a minimum MySQL version of 5.6. See: %s', 'woocommerce' ), esc_html( $mysql_version ), '<a href="https://wordpress.org/about/requirements/" target="_blank">' . __( 'WordPress Requirements', 'woocommerce' ) . '</a>' ) . '</mark>';
} else {
echo '<mark class="yes">' . esc_html( $mysql_version ) . '</mark>';
}
?>
</td>
</tr>
<?php endif; ?>
<tr>
<td data-export-label="Max Upload Size"><?php _e( 'Max Upload Size', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'The largest filesize that can be uploaded to your WordPress installation.', 'woocommerce' ) ); ?></td>
@ -344,7 +346,6 @@ if ( ! defined( 'ABSPATH' ) ) {
'woocommerce_sessions',
'woocommerce_api_keys',
'woocommerce_attribute_taxonomies',
'woocommerce_termmeta',
'woocommerce_downloadable_product_permissions',
'woocommerce_order_items',
'woocommerce_order_itemmeta',
@ -357,6 +358,10 @@ if ( ! defined( 'ABSPATH' ) ) {
'woocommerce_payment_tokenmeta',
);
if ( get_option( 'db_version' ) < 34370 ) {
$tables[] = 'woocommerce_termmeta';
}
foreach ( $tables as $table ) {
?>
<tr>
@ -376,7 +381,7 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( file_exists( WC_Geolocation::get_local_database_path() ) ) {
echo '<mark class="yes"><span class="dashicons dashicons-yes"></span> <code class="private">' . esc_html( WC_Geolocation::get_local_database_path() ) . '</code></mark> ';
} else {
printf( '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'The MaxMind GeoIP Database does not exist - Geolocation will not function. You can download and install it manually from %s to the path: %s', 'woocommerce' ), make_clickable( 'http://dev.maxmind.com/geoip/legacy/geolite/' ), '<code class="private">' . WC_Geolocation::get_local_database_path() . '</code>' ) . '</mark>', WC_LOG_DIR );
printf( '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'The MaxMind GeoIP Database does not exist - Geolocation will not function. You can download and install it manually from %1$s to the path: %2$s', 'woocommerce' ), make_clickable( 'http://dev.maxmind.com/geoip/legacy/geolite/' ), '<code class="private">' . WC_Geolocation::get_local_database_path() . '</code>' ) . '</mark>', WC_LOG_DIR );
}
?></td>
</tr>
@ -567,6 +572,9 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! $page_id ) {
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . __( 'Page not set', 'woocommerce' ) . '</mark>';
$error = true;
} else if ( ! get_post( $page_id ) ) {
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . __( 'Page ID is set, but the page does not exist', 'woocommerce' ) . '</mark>';
$error = true;
} else if ( get_post_status( $page_id ) !== 'publish' ) {
echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Page visibility should be %spublic%s', 'woocommerce' ), '<a href="https://codex.wordpress.org/Content_Visibility" target="_blank">', '</a>' ) . '</mark>';
$error = true;
@ -658,7 +666,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<td data-export-label="Child Theme"><?php _e( 'Child Theme', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'Displays whether or not the current theme is a child theme.', 'woocommerce' ) ); ?></td>
<td><?php
echo is_child_theme() ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<span class="dashicons dashicons-no-alt"></span> &ndash; ' . sprintf( __( 'If you\'re modifying WooCommerce on a parent theme you didn\'t build personally, then we recommend using a child theme. See: <a href="%s" target="_blank">How to create a child theme</a>', 'woocommerce' ), 'http://codex.wordpress.org/Child_Themes' );
echo is_child_theme() ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<span class="dashicons dashicons-no-alt"></span> &ndash; ' . sprintf( __( 'If you\'re modifying WooCommerce on a parent theme you didn\'t build personally, then we recommend using a child theme. See: <a href="%s" target="_blank">How to create a child theme</a>', 'woocommerce' ), 'https://codex.wordpress.org/Child_Themes' );
?></td>
</tr>
<?php
@ -708,8 +716,14 @@ if ( ! defined( 'ABSPATH' ) ) {
</tr>
</thead>
<tbody>
<?php if ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ) : ?>
<tr>
<td data-export-label="Overrides"><?php _e( 'Archive Template', 'woocommerce' ); ?>:</td>
<td class="help">&nbsp;</td>
<td><?php _e( 'Your theme has a woocommerce.php file, you will not be able to override the woocommerce/archive-product.php custom template since woocommerce.php has priority over archive-product.php. This is intended to prevent display issues.', 'woocommerce' ); ?></td>
</tr>
<?php endif ?>
<?php
$template_paths = apply_filters( 'woocommerce_template_overrides_scan_paths', array( 'WooCommerce' => WC()->plugin_path() . '/templates/' ) );
$scanned_files = array();
$found_files = array();

View File

@ -13,7 +13,7 @@ $tabs = array(
'tools' => __( 'Tools', 'woocommerce' ),
'logs' => __( 'Logs', 'woocommerce' ),
);
$tabs = apply_filters( 'woocommerce_admin_status_tabs', $tabs );
?>
<div class="wrap woocommerce">
<nav class="nav-tab-wrapper woo-nav-tab-wrapper">
@ -25,7 +25,7 @@ $tabs = array(
}
?>
</nav>
<h1 class="screen-reader-text"><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1>
<h1 class="screen-reader-text"><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1>
<?php
switch ( $current_tab ) {
case "tools" :
@ -35,7 +35,11 @@ $tabs = array(
WC_Admin_Status::status_logs();
break;
default :
WC_Admin_Status::status_report();
if ( array_key_exists( $current_tab, $tabs ) && has_action( 'woocommerce_admin_status_content_' . $current_tab ) ) {
do_action( 'woocommerce_admin_status_content_' . $current_tab );
} else {
WC_Admin_Status::status_report();
}
break;
}
?>

View File

@ -12,12 +12,12 @@ if ( ! defined( 'ABSPATH' ) ) {
<p class="main"><strong><?php _e( 'New feature: shipping zones!', 'woocommerce' ); ?></strong></p>
<p><?php _e( 'A shipping zone is a group of regions that can be assigned different shipping methods and rates.', 'woocommerce' ); ?></p>
<p><?php _e( 'Legacy shipping methods (Flat Rate, International, Local Pickup and Delivery and Free Shipping) are deprecated and <em>will be removed in future versions of WooCommerce</em>, but will continue to function as normal for now. We recommend disabling these shipping methods and instead setting up new rates within shipping zones as soon as possible.', 'woocommerce' ); ?></p>
<p><?php _e( 'Legacy shipping methods (Flat Rate, International Flat Rate, Local Pickup and Delivery, and Free Shipping) are deprecated but will continue to work as normal for now. <b><em>They will be removed in future versions of WooCommerce</em></b>. We recommend disabling these and setting up new rates within shipping zones as soon as possible.', 'woocommerce' ); ?></p>
<p class="submit">
<?php if ( empty( $_GET['page'] ) || empty( $_GET['tab'] ) || 'wc-settings' !== $_GET['page'] || 'shipping' !== $_GET['tab'] ) : ?>
<a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>"><?php _e( 'Setup shipping zones', 'woocommerce' ); ?></a>
<?php endif; ?>
<a class="button-secondary" href="<?php echo esc_url( 'https://docs.woothemes.com/document/setting-up-shipping-zones/' ); ?>"><?php _e( 'Lean more about shipping zones', 'woocommerce' ); ?></a>
<a class="button-secondary" href="<?php echo esc_url( 'https://docs.woothemes.com/document/setting-up-shipping-zones/' ); ?>"><?php _e( 'Learn more about shipping zones', 'woocommerce' ); ?></a>
</p>
</div>

View File

@ -16,6 +16,6 @@ if ( ! defined( 'ABSPATH' ) ) {
<p class="submit">
<a class="button-primary" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ); ?>"><?php _e( 'Setup shipping zones', 'woocommerce' ); ?></a>
<a class="button-secondary" href="<?php echo esc_url( 'https://docs.woothemes.com/document/setting-up-shipping-zones/' ); ?>"><?php _e( 'Lean more about shipping zones', 'woocommerce' ); ?></a>
<a class="button-secondary" href="<?php echo esc_url( 'https://docs.woothemes.com/document/setting-up-shipping-zones/' ); ?>"><?php _e( 'Learn more about shipping zones', 'woocommerce' ); ?></a>
</p>
</div>

View File

@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<div id="message" class="updated woocommerce-message wc-connect">
<p><?php _e( '<strong>WooCommerce Data Update Required</strong> &#8211; We just need to update your install to the latest version', 'woocommerce' ); ?></p>
<p><?php _e( '<strong>WooCommerce Data Update Required</strong> &#8211; We need to update your store\'s database to the latest version.', 'woocommerce' ); ?></p>
<p class="submit"><a href="<?php echo esc_url( add_query_arg( 'do_update_woocommerce', 'true', admin_url( 'admin.php?page=wc-settings' ) ) ); ?>" class="wc-update-now button-primary"><?php _e( 'Run the updater', 'woocommerce' ); ?></a></p>
</div>
<script type="text/javascript">

View File

@ -0,0 +1,15 @@
<?php
/**
* Admin View: Notice - Updated
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="message" class="updated woocommerce-message wc-connect">
<a class="woocommerce-message-close notice-dismiss" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'updating' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php _e( 'Dismiss', 'woocommerce' ); ?></a>
<p><?php _e( 'WooCommerce data update complete. Thank you for updating to the latest version!', 'woocommerce' ); ?></p>
</div>

View File

@ -0,0 +1,13 @@
<?php
/**
* Admin View: Notice - Updating
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="message" class="updated woocommerce-message wc-connect">
<p><?php _e( '<strong>WooCommerce Data Updating</strong> &#8211; Your database is being updated in the background.', 'woocommerce' ); ?></p>
</div>

View File

@ -23,6 +23,25 @@ class WC_REST_Authentication {
add_filter( 'rest_post_dispatch', array( $this, 'send_unauthorized_headers' ), 50 );
}
/**
* Check if is request to our REST API.
*
* @return bool
*/
protected function is_request_to_rest_api() {
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
return false;
}
// Check if our endpoint.
$woocommerce = false !== strpos( $_SERVER['REQUEST_URI'], 'wp-json/wc/' );
// Allow third party plugins use our authentication methods.
$third_party = false !== strpos( $_SERVER['REQUEST_URI'], 'wp-json/wc-' );
return apply_filters( 'woocommerce_rest_is_request_to_rest_api', $woocommerce || $third_party );
}
/**
* Authenticate user.
*
@ -30,8 +49,8 @@ class WC_REST_Authentication {
* @return int|false
*/
public function authenticate( $user_id ) {
// Do not authenticate twice!
if ( ! empty( $user_id ) ) {
// Do not authenticate twice and check if is a request to our endpoint in the WP REST API.
if ( ! empty( $user_id ) || ! $this->is_request_to_rest_api() ) {
return $user_id;
}

View File

@ -102,6 +102,16 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );
}
/**
@ -453,6 +463,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'discount_type' => array(
'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ),
'type' => 'string',
'default' => 'fixed_cart',
'enum' => array_keys( wc_get_coupon_types() ),
'context' => array( 'view', 'edit' ),
),
@ -475,6 +486,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'individual_use' => array(
'description' => __( 'Whether coupon can only be used individually.', 'woocommerce' ),
'type' => 'boolean',
'default' => false,
'context' => array( 'view', 'edit' ),
),
'product_ids' => array(
@ -493,7 +505,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'context' => array( 'view', 'edit' ),
),
'usage_limit_per_user' => array(
'description' => __( 'How many times the coupon can be user per customer.', 'woocommerce' ),
'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
),
@ -505,6 +517,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'free_shipping' => array(
'description' => __( 'Define if can be applied for free shipping.', 'woocommerce' ),
'type' => 'boolean',
'default' => false,
'context' => array( 'view', 'edit' ),
),
'product_categories' => array(
@ -520,6 +533,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'exclude_sale_items' => array(
'description' => __( 'Define if should not apply when have sale items.', 'woocommerce' ),
'type' => 'boolean',
'default' => false,
'context' => array( 'view', 'edit' ),
),
'minimum_amount' => array(

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Customers controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Customer_Downloads_Controller extends WP_REST_Controller {
class WC_REST_Customer_Downloads_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Customers controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Customers_Controller extends WP_REST_Controller {
class WC_REST_Customers_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.
@ -104,6 +104,16 @@ class WC_REST_Customers_Controller extends WP_REST_Controller {
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );
}
/**
@ -182,6 +192,20 @@ class WC_REST_Customers_Controller extends WP_REST_Controller {
return true;
}
/**
* Check if a given request has access batch create, update and delete items.
*
* @param WP_REST_Request $request Full details about the request.
* @return boolean
*/
public function batch_items_permissions_check( $request ) {
if ( ! wc_rest_check_user_permissions( 'batch' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to manipule this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
/**
* Get all customers.
*

View File

@ -14,6 +14,34 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class WC_REST_Exception extends WC_API_Exception {
class WC_REST_Exception extends Exception {
/**
* Sanitized error code.
*
* @var string
*/
protected $error_code;
/**
* Setup exception.
*
* @param string $error_code Machine-readable error code.
* @param string $error_message User-friendly translated error message.
* @param int $http_status_code HTTP status code to respond with.
*/
public function __construct( $error_code, $error_message, $http_status_code ) {
$this->error_code = $error_code;
parent::__construct( $error_message, $http_status_code );
}
/**
* Returns the error code.
*
* @return string
*/
public function getErrorCode() {
return $this->error_code;
}
}

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Order Notes controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Order_Notes_Controller extends WP_REST_Controller {
class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.

View File

@ -99,6 +99,16 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );
}
/**

View File

@ -39,16 +39,20 @@ class WC_REST_Product_Attribute_Terms_Controller extends WC_REST_Terms_Controlle
/**
* Prepare a single product attribute term output for response.
*
* @param obj $item Term object.
* @param WP_Term $item Term object.
* @param WP_REST_Request $request
* @return WP_REST_Response $response
*/
public function prepare_item_for_response( $item, $request ) {
// Get term order.
$menu_order = get_woocommerce_term_meta( $item->term_id, 'order_' . $this->taxonomy );
$data = array(
'id' => (int) $item->term_id,
'name' => $item->name,
'slug' => $item->slug,
'count' => (int) $item->count,
'id' => (int) $item->term_id,
'name' => $item->name,
'slug' => $item->slug,
'menu_order' => (int) $menu_order,
'count' => (int) $item->count,
);
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
@ -71,6 +75,21 @@ class WC_REST_Product_Attribute_Terms_Controller extends WC_REST_Terms_Controlle
return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
}
/**
* Update term meta fields.
*
* @param WP_Term $term
* @param WP_REST_Request $request
* @return bool|WP_Error
*/
protected function update_term_meta_fields( $term, $request ) {
$id = (int) $term->term_id;
update_woocommerce_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] );
return true;
}
/**
* Get the Attribute Term's schema, conforming to JSON Schema.
*
@ -104,10 +123,15 @@ class WC_REST_Product_Attribute_Terms_Controller extends WC_REST_Terms_Controlle
'sanitize_callback' => 'sanitize_title',
),
),
'menu_order' => array(
'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
),
'count' => array(
'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'woocommerce' ),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Product Attributes controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Product_Attributes_Controller extends WP_REST_Controller {
class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.

View File

@ -46,7 +46,7 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Terms_Controller {
/**
* Prepare a single product category output for response.
*
* @param obj $item Term object.
* @param WP_Term $item Term object.
* @param WP_REST_Request $request
* @return WP_REST_Response $response
*/
@ -60,6 +60,9 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Terms_Controller {
$image = wp_get_attachment_url( $image_id );
}
// Get category order.
$menu_order = get_woocommerce_term_meta( $item->term_id, 'order' );
$data = array(
'id' => (int) $item->term_id,
'name' => $item->name,
@ -68,6 +71,7 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Terms_Controller {
'description' => $item->description,
'display' => $display_type ? $display_type : 'default',
'image' => $image ? esc_url( $image ) : '',
'menu_order' => (int) $menu_order,
'count' => (int) $item->count,
);
@ -102,6 +106,7 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Terms_Controller {
$id = (int) $term->term_id;
update_woocommerce_term_meta( $id, 'display_type', $request['display'] );
update_woocommerce_term_meta( $id, 'order', $request['menu_order'] );
if ( ! empty( $request['image'] ) ) {
$upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image'] ) );
@ -180,10 +185,15 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Terms_Controller {
'format' => 'uri',
'context' => array( 'view', 'edit' ),
),
'menu_order' => array(
'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
),
'count' => array(
'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'woocommerce' ),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Products controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Product_Reviews_Controller extends WP_REST_Controller {
class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.

View File

@ -129,7 +129,7 @@ class WC_REST_Product_Shipping_Classes_Controller extends WC_REST_Terms_Controll
'count' => array(
'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'woocommerce' ),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),

View File

@ -123,7 +123,7 @@ class WC_REST_Product_Tags_Controller extends WC_REST_Terms_Controller {
'count' => array(
'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'woocommerce' ),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),

View File

@ -100,6 +100,16 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
'schema' => array( $this, 'get_public_batch_schema' ),
) );
}
/**
@ -847,6 +857,9 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
}
}
// Default total sales.
add_post_meta( $product_id, 'total_sales', '0', true );
// Virtual.
if ( isset( $request['virtual'] ) ) {
update_post_meta( $product->id, '_virtual', true === $request['virtual'] ? 'yes' : 'no' );

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Report Sales controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Report_Sales_Controller extends WP_REST_Controller {
class WC_REST_Report_Sales_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.

View File

@ -18,9 +18,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* REST API Reports controller class.
*
* @package WooCommerce/API
* @extends WP_REST_Controller
* @extends WC_REST_Controller
*/
class WC_REST_Reports_Controller extends WP_REST_Controller {
class WC_REST_Reports_Controller extends WC_REST_Controller {
/**
* Endpoint namespace.

Some files were not shown because too many files have changed in this diff Show More