Bring up-to-date with master

This commit is contained in:
Claudiu Lodromanean 2017-02-06 10:10:41 -08:00
commit e45adc14ed
126 changed files with 1776 additions and 1154 deletions

View File

@ -86,7 +86,7 @@ If WooCommerce is already 100% translated for your language, join the team anywa
### Translating Video Tutorials
Another valuable way to help is by translating our growing library of WooCommerce video tutorials. Check out our [Video SRTs project](https://www.transifex.com/projects/p/video-srts/) and join the team for your language. If there isn't one, please request the new language and we will add it for you.
Another valuable way to help is by translating our growing library of WooCommerce video tutorials. Check out the [Translating Our Videos](https://docs.woocommerce.com/document/translating-our-videos/) doc and join in!
By translating video tutorials you'll be helping non-English speaking users and people affected by disabilities to get to grips with using WooCommerce for the first time, and to go on and create their businesses and make a living! That's something to be proud of and if you choose to dive into this area, we salute you.

BIN
.github/wiki.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2611,9 +2611,10 @@ table.wc_shipping {
}
}
.wc-shipping-zone-postcodes-toggle {
margin: 0;
margin: 0.5em 0 0;
font-size: 0.9em;
text-decoration: underline;
display: block;
}
.wc-shipping-zone-postcodes-toggle + .wc-shipping-zone-postcodes {
display:none;
@ -2628,6 +2629,9 @@ table.wc_shipping {
}
}
}
.wc-shipping-zone-settings + p.submit {
margin-top: 0;
}
table {
tr, tr:hover {
table.wc-shipping-zone-methods {
@ -2679,6 +2683,13 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
position: relative;
padding: 7.5em 7.5% !important;
border-bottom: 2px solid #eee2ec;
&.wc-shipping-zone-method-blank-state {
padding: 2em !important;
p {
margin-bottom: 0;
}
}
p, li {
color: #a46497;
font-size: 1.5em;
@ -2848,7 +2859,7 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
}
}
.wc-shipping-zone-method-title {
width: 33%;
width: 25%;
.wc-shipping-zone-method-delete {
color: red;
}
@ -2864,6 +2875,9 @@ table.wc-shipping-zones, table.wc-shipping-zone-methods, table.wc-shipping-class
margin-top: 3px;
}
}
.wc-shipping-zone-method-type {
display: block;
}
tfoot {
input, select {
vertical-align: middle !important;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -555,14 +555,5 @@
float: left;
}
}
form {
.form-row-first,
.form-row-last {
float: right;
}
.form-row-last {
float: left;
}
}
}
}

View File

@ -136,6 +136,7 @@ jQuery(function( $ ) {
exclude_series = exclude_series.split( ',' );
var xaxes_label = $( this ).data( 'xaxes' );
var groupby = $( this ) .data( 'groupby' );
var index_type = $( this ).data( 'index_type' );
var export_format = $( this ).data( 'export' );
var csv_data = 'data:application/csv;charset=utf-8,';
var s, series_data, d;
@ -217,10 +218,14 @@ jQuery(function( $ ) {
$.each( xaxis, function( index, value ) {
var date = new Date( parseInt( index, 10 ) );
if ( groupby === 'day' ) {
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '-' + date.getUTCDate() + '",';
if ( 'none' === index_type ) {
csv_data += '"' + index + '",';
} else {
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '",';
if ( groupby === 'day' ) {
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '-' + date.getUTCDate() + '",';
} else {
csv_data += '"' + date.getUTCFullYear() + '-' + parseInt( date.getUTCMonth() + 1, 10 ) + '",';
}
}
for ( var d = 0; d < value.length; ++d ) {

View File

@ -1 +1 @@
jQuery(function(a){function b(b,c,d){a('<div class="chart-tooltip">'+d+"</div>").css({top:c-16,left:b+20}).appendTo("body").fadeIn(200)}var c=null,d=null;a(".chart-placeholder").bind("plothover",function(e,f,g){if(g){if((c!==g.dataIndex||d!==g.seriesIndex)&&(c=g.dataIndex,d=g.seriesIndex,a(".chart-tooltip").remove(),g.series.points.show||g.series.enable_tooltip)){var h=g.series.data[g.dataIndex][1],i="";g.series.prepend_label&&(i=i+g.series.label+": "),g.series.prepend_tooltip&&(i+=g.series.prepend_tooltip),i+=h,g.series.append_tooltip&&(i+=g.series.append_tooltip),g.series.pie.show?b(f.pageX,f.pageY,i):b(g.pageX,g.pageY,i)}}else a(".chart-tooltip").remove(),c=null}),a(".wc_sparkline.bars").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),bars:{fillColor:a(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:a(this).data("barwidth"),align:"center"},shadowSize:0}];a.plot(a(this),d,c)}),a(".wc_sparkline.lines").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}];a.plot(a(this),d,c)});var e=a(".range_datepicker").datepicker({changeMonth:!0,changeYear:!0,defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,maxDate:"+0D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(b){var c=a(this).is(".from")?"minDate":"maxDate",d=a(this).data("datepicker"),f=a.datepicker.parseDate(d.settings.dateFormat||a.datepicker._defaults.dateFormat,b,d.settings);e.not(this).datepicker("option",c,f)}}),f=document.createElement("a");"undefined"==typeof f.download&&a(".export_csv").hide(),a(".export_csv").click(function(){var b=a(this).data("exclude_series")||"";b=b.toString(),b=b.split(",");var c,d,e,f=a(this).data("xaxes"),g=a(this).data("groupby"),h=a(this).data("export"),i="data:application/csv;charset=utf-8,";if("table"===h)a(this).offsetParent().find("thead tr,tbody tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();b=b.replace("[?]","").replace("#",""),i+='"'+b+'",'}),i=i.substring(0,i.length-1),i+="\n"}),a(this).offsetParent().find("tfoot tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();if(b=b.replace("[?]","").replace("#",""),i+='"'+b+'",',a(this).attr("colspan")>0)for(m=1;m<a(this).attr("colspan");m++)i+='"",'}),i=i.substring(0,i.length-1),i+="\n"});else{if(!window.main_chart)return!1;var j=window.main_chart.getData(),k=[];for(i+='"'+f+'",',a.each(j,function(c,d){b&&a.inArray(c.toString(),b)!==-1||k.push(d)}),c=0;c<k.length;++c)i+='"'+k[c].label+'",';i=i.substring(0,i.length-1),i+="\n";var l={};for(c=0;c<k.length;++c)for(d=k[c].data,e=0;e<d.length;++e){l[d[e][0]]=[];for(var m=0;m<k.length;++m)l[d[e][0]].push(0)}for(c=0;c<k.length;++c)for(d=k[c].data,e=0;e<d.length;++e)l[d[e][0]][c]=d[e][1];a.each(l,function(a,b){var c=new Date(parseInt(a,10));i+="day"===g?'"'+c.getUTCFullYear()+"-"+parseInt(c.getUTCMonth()+1,10)+"-"+c.getUTCDate()+'",':'"'+c.getUTCFullYear()+"-"+parseInt(c.getUTCMonth()+1,10)+'",';for(var d=0;d<b.length;++d){var e=b[d];Math.round(e)!==e&&(e=parseFloat(e),e=e.toFixed(2)),i+='"'+e+'",'}i=i.substring(0,i.length-1),i+="\n"})}return a(this).attr("href",encodeURI(i)),!0})});
jQuery(function(a){function b(b,c,d){a('<div class="chart-tooltip">'+d+"</div>").css({top:c-16,left:b+20}).appendTo("body").fadeIn(200)}var c=null,d=null;a(".chart-placeholder").bind("plothover",function(e,f,g){if(g){if((c!==g.dataIndex||d!==g.seriesIndex)&&(c=g.dataIndex,d=g.seriesIndex,a(".chart-tooltip").remove(),g.series.points.show||g.series.enable_tooltip)){var h=g.series.data[g.dataIndex][1],i="";g.series.prepend_label&&(i=i+g.series.label+": "),g.series.prepend_tooltip&&(i+=g.series.prepend_tooltip),i+=h,g.series.append_tooltip&&(i+=g.series.append_tooltip),g.series.pie.show?b(f.pageX,f.pageY,i):b(g.pageX,g.pageY,i)}}else a(".chart-tooltip").remove(),c=null}),a(".wc_sparkline.bars").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),bars:{fillColor:a(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:a(this).data("barwidth"),align:"center"},shadowSize:0}];a.plot(a(this),d,c)}),a(".wc_sparkline.lines").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}];a.plot(a(this),d,c)});var e=a(".range_datepicker").datepicker({changeMonth:!0,changeYear:!0,defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,maxDate:"+0D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(b){var c=a(this).is(".from")?"minDate":"maxDate",d=a(this).data("datepicker"),f=a.datepicker.parseDate(d.settings.dateFormat||a.datepicker._defaults.dateFormat,b,d.settings);e.not(this).datepicker("option",c,f)}}),f=document.createElement("a");"undefined"==typeof f.download&&a(".export_csv").hide(),a(".export_csv").click(function(){var b=a(this).data("exclude_series")||"";b=b.toString(),b=b.split(",");var c,d,e,f=a(this).data("xaxes"),g=a(this).data("groupby"),h=a(this).data("index_type"),i=a(this).data("export"),j="data:application/csv;charset=utf-8,";if("table"===i)a(this).offsetParent().find("thead tr,tbody tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();b=b.replace("[?]","").replace("#",""),j+='"'+b+'",'}),j=j.substring(0,j.length-1),j+="\n"}),a(this).offsetParent().find("tfoot tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();if(b=b.replace("[?]","").replace("#",""),j+='"'+b+'",',a(this).attr("colspan")>0)for(n=1;n<a(this).attr("colspan");n++)j+='"",'}),j=j.substring(0,j.length-1),j+="\n"});else{if(!window.main_chart)return!1;var k=window.main_chart.getData(),l=[];for(j+='"'+f+'",',a.each(k,function(c,d){b&&a.inArray(c.toString(),b)!==-1||l.push(d)}),c=0;c<l.length;++c)j+='"'+l[c].label+'",';j=j.substring(0,j.length-1),j+="\n";var m={};for(c=0;c<l.length;++c)for(d=l[c].data,e=0;e<d.length;++e){m[d[e][0]]=[];for(var n=0;n<l.length;++n)m[d[e][0]].push(0)}for(c=0;c<l.length;++c)for(d=l[c].data,e=0;e<d.length;++e)m[d[e][0]][c]=d[e][1];a.each(m,function(a,b){var c=new Date(parseInt(a,10));j+="none"===h?'"'+a+'",':"day"===g?'"'+c.getUTCFullYear()+"-"+parseInt(c.getUTCMonth()+1,10)+"-"+c.getUTCDate()+'",':'"'+c.getUTCFullYear()+"-"+parseInt(c.getUTCMonth()+1,10)+'",';for(var d=0;d<b.length;++d){var e=b[d];Math.round(e)!==e&&(e=parseFloat(e),e=e.toFixed(2)),j+='"'+e+'",'}j=j.substring(0,j.length-1),j+="\n"})}return a(this).attr("href",encodeURI(j)),!0})});

View File

@ -3,53 +3,48 @@ jQuery( function( $ ) {
function getEnhancedSelectFormatString() {
var formatString = {
formatMatches: function( matches ) {
if ( 1 === matches ) {
return wc_enhanced_select_params.i18n_matches_1;
}
return wc_enhanced_select_params.i18n_matches_n.replace( '%qty%', matches );
},
formatNoMatches: function() {
noResults: function() {
return wc_enhanced_select_params.i18n_no_matches;
},
formatAjaxError: function() {
errorLoading: function() {
return wc_enhanced_select_params.i18n_ajax_error;
},
formatInputTooShort: function( input, min ) {
var number = min - input.length;
inputTooShort: function( args ) {
var remainingChars = args.minimum - args.input.length;
if ( 1 === number ) {
if ( 1 === remainingChars ) {
return wc_enhanced_select_params.i18n_input_too_short_1;
}
return wc_enhanced_select_params.i18n_input_too_short_n.replace( '%qty%', number );
return wc_enhanced_select_params.i18n_input_too_short_n.replace( '%qty%', remainingChars );
},
formatInputTooLong: function( input, max ) {
var number = input.length - max;
inputTooLong: function( args ) {
var overChars = args.input.length - args.maximum;
if ( 1 === number ) {
if ( 1 === overChars ) {
return wc_enhanced_select_params.i18n_input_too_long_1;
}
return wc_enhanced_select_params.i18n_input_too_long_n.replace( '%qty%', number );
return wc_enhanced_select_params.i18n_input_too_long_n.replace( '%qty%', overChars );
},
formatSelectionTooBig: function( limit ) {
if ( 1 === limit ) {
maximumSelected: function( args ) {
if ( args.maximum === 1 ) {
return wc_enhanced_select_params.i18n_selection_too_long_1;
}
return wc_enhanced_select_params.i18n_selection_too_long_n.replace( '%qty%', limit );
return wc_enhanced_select_params.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
},
formatLoadMore: function() {
loadingMore: function() {
return wc_enhanced_select_params.i18n_load_more;
},
formatSearching: function() {
searching: function() {
return wc_enhanced_select_params.i18n_searching;
}
};
var language = { 'language' : formatString };
return formatString;
return language;
}
$( document.body )

View File

@ -1 +1 @@
jQuery(function(a){function b(){var a={formatMatches:function(a){return 1===a?wc_enhanced_select_params.i18n_matches_1:wc_enhanced_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_enhanced_select_params.i18n_no_matches},formatAjaxError:function(){return wc_enhanced_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_enhanced_select_params.i18n_input_too_short_1:wc_enhanced_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_enhanced_select_params.i18n_input_too_long_1:wc_enhanced_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_enhanced_select_params.i18n_selection_too_long_1:wc_enhanced_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_enhanced_select_params.i18n_load_more},formatSearching:function(){return wc_enhanced_select_params.i18n_searching}};return a}a(document.body).on("wc-enhanced-select-init",function(){a(":input.wc-enhanced-select, :input.chosen_select").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-enhanced-select-nostd, :input.chosen_select_nostd").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!0,placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-product-search").filter(":not(.enhanced)").each(function(){var c={allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b.term,action:a(this).data("action")||"woocommerce_json_search_products_and_variations",security:wc_enhanced_select_params.search_products_nonce,exclude:a(this).data("exclude"),include:a(this).data("include"),limit:a(this).data("limit")}},processResults:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};if(c=a.extend(c,b()),a(this).select2(c).addClass("enhanced"),a(this).data("sortable")){var d=a(this),e=a(this).next(".select2-container").find("ul.select2-selection__rendered");e.sortable({placeholder:"ui-state-highlight select2-selection__choice",forcePlaceholderSize:!0,items:"li:not(.select2-search__field)",tolerance:"pointer",stop:function(){a(e.find(".select2-selection__choice").get().reverse()).each(function(){var b=a(this).data("data").id,c=d.find('option[value="'+b+'"]')[0];d.prepend(c)})}})}}),a(":input.wc-customer-search").filter(":not(.enhanced)").each(function(){var c={allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b.term,action:"woocommerce_json_search_customers",security:wc_enhanced_select_params.search_customers_nonce,exclude:a(this).data("exclude")}},processResults:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};if(c=a.extend(c,b()),a(this).select2(c).addClass("enhanced"),a(this).data("sortable")){var d=a(this),e=a(this).next(".select2-container").find("ul.select2-selection__rendered");e.sortable({placeholder:"ui-state-highlight select2-selection__choice",forcePlaceholderSize:!0,items:"li:not(.select2-search__field)",tolerance:"pointer",stop:function(){a(e.find(".select2-selection__choice").get().reverse()).each(function(){var b=a(this).data("data").id,c=d.find('option[value="'+b+'"]')[0];d.prepend(c)})}})}})}).on("wc_backbone_modal_before_remove",function(){a(".wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search").filter(".select2-hidden-accessible").select2("close")}).trigger("wc-enhanced-select-init"),a("html").on("click",function(b){this===b.target&&a(".wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search").filter(".select2-hidden-accessible").select2("close")})});
jQuery(function(a){function b(){var a={noResults:function(){return wc_enhanced_select_params.i18n_no_matches},errorLoading:function(){return wc_enhanced_select_params.i18n_ajax_error},inputTooShort:function(a){var b=a.minimum-a.input.length;return 1===b?wc_enhanced_select_params.i18n_input_too_short_1:wc_enhanced_select_params.i18n_input_too_short_n.replace("%qty%",b)},inputTooLong:function(a){var b=a.input.length-a.maximum;return 1===b?wc_enhanced_select_params.i18n_input_too_long_1:wc_enhanced_select_params.i18n_input_too_long_n.replace("%qty%",b)},maximumSelected:function(a){return 1===a.maximum?wc_enhanced_select_params.i18n_selection_too_long_1:wc_enhanced_select_params.i18n_selection_too_long_n.replace("%qty%",a.maximum)},loadingMore:function(){return wc_enhanced_select_params.i18n_load_more},searching:function(){return wc_enhanced_select_params.i18n_searching}},b={language:a};return b}a(document.body).on("wc-enhanced-select-init",function(){a(":input.wc-enhanced-select, :input.chosen_select").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-enhanced-select-nostd, :input.chosen_select_nostd").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!0,placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-product-search").filter(":not(.enhanced)").each(function(){var c={allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b.term,action:a(this).data("action")||"woocommerce_json_search_products_and_variations",security:wc_enhanced_select_params.search_products_nonce,exclude:a(this).data("exclude"),include:a(this).data("include"),limit:a(this).data("limit")}},processResults:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};if(c=a.extend(c,b()),a(this).select2(c).addClass("enhanced"),a(this).data("sortable")){var d=a(this),e=a(this).next(".select2-container").find("ul.select2-selection__rendered");e.sortable({placeholder:"ui-state-highlight select2-selection__choice",forcePlaceholderSize:!0,items:"li:not(.select2-search__field)",tolerance:"pointer",stop:function(){a(e.find(".select2-selection__choice").get().reverse()).each(function(){var b=a(this).data("data").id,c=d.find('option[value="'+b+'"]')[0];d.prepend(c)})}})}}),a(":input.wc-customer-search").filter(":not(.enhanced)").each(function(){var c={allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b.term,action:"woocommerce_json_search_customers",security:wc_enhanced_select_params.search_customers_nonce,exclude:a(this).data("exclude")}},processResults:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};if(c=a.extend(c,b()),a(this).select2(c).addClass("enhanced"),a(this).data("sortable")){var d=a(this),e=a(this).next(".select2-container").find("ul.select2-selection__rendered");e.sortable({placeholder:"ui-state-highlight select2-selection__choice",forcePlaceholderSize:!0,items:"li:not(.select2-search__field)",tolerance:"pointer",stop:function(){a(e.find(".select2-selection__choice").get().reverse()).each(function(){var b=a(this).data("data").id,c=d.find('option[value="'+b+'"]')[0];d.prepend(c)})}})}})}).on("wc_backbone_modal_before_remove",function(){a(".wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search").filter(".select2-hidden-accessible").select2("close")}).trigger("wc-enhanced-select-init"),a("html").on("click",function(b){this===b.target&&a(".wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search").filter(".select2-hidden-accessible").select2("close")})});

View File

@ -489,22 +489,24 @@ jQuery( function( $ ) {
* @param {JQuery Object} $form The cart form.
*/
quantity_update: function( $form ) {
// Provide the submit button value because wc-form-handler expects it.
$( '<input />' ).attr( 'type', 'hidden' )
.attr( 'name', 'update_cart' )
.attr( 'value', 'Update Cart' )
.appendTo( $form );
block( $form );
block( $( 'div.cart_totals' ) );
// Provide the submit button value because wc-form-handler expects it.
$( '<input />' ).attr( 'type', 'hidden' )
.attr( 'name', 'update_cart' )
.attr( 'value', 'Update Cart' )
.appendTo( $form );
// Make call to actual form post URL.
$.ajax( {
type: $form.attr( 'method' ),
url: $form.attr( 'action' ),
data: $form.serialize(),
dataType: 'html',
success: update_wc_div,
success: function( response ) {
update_wc_div( response );
},
complete: function() {
unblock( $form );
unblock( $( 'div.cart_totals' ) );

File diff suppressed because one or more lines are too long

View File

@ -290,6 +290,20 @@ jQuery( function( $ ) {
var termsCheckBoxChecked = $( '#terms' ).prop( 'checked' );
// Save payment details to a temporary object
var paymentDetails = {};
$( '.payment_box input' ).each( function() {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
paymentDetails[ ID ] = $( this ).prop( 'checked' );
} else {
paymentDetails[ ID ] = $( this ).val();
}
}
});
// Always update the fragments
if ( data && data.fragments ) {
$.each( data.fragments, function ( key, value ) {
@ -303,6 +317,21 @@ jQuery( function( $ ) {
$( '#terms' ).prop( 'checked', true );
}
// Fill in the payment details if possible
if ( ! $.isEmptyObject( paymentDetails ) ) {
$( '.payment_box input' ).each( function() {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
$( this ).prop( 'checked', paymentDetails[ ID ] ).change();
} else {
$( this ).val( paymentDetails[ ID ] ).change();
}
}
});
}
// Check for error
if ( 'failure' === data.result ) {
@ -446,7 +475,7 @@ jQuery( function( $ ) {
},
submit_error: function( error_message ) {
$( '.woocommerce-error, .woocommerce-message' ).remove();
wc_checkout_form.$checkout_form.prepend( error_message );
wc_checkout_form.$checkout_form.prepend( '<div class="woocommerce-NoticeGroup-updateOrderReview">' + error_message + '</div>' );
wc_checkout_form.$checkout_form.removeClass( 'processing' ).unblock();
wc_checkout_form.$checkout_form.find( '.input-text, select, input:checkbox' ).blur();
$( 'html, body' ).animate({

File diff suppressed because one or more lines are too long

View File

@ -8,53 +8,48 @@ jQuery( function( $ ) {
function getEnhancedSelectFormatString() {
var formatString = {
formatMatches: function( matches ) {
if ( 1 === matches ) {
return wc_country_select_params.i18n_matches_1;
}
return wc_country_select_params.i18n_matches_n.replace( '%qty%', matches );
},
formatNoMatches: function() {
noResults: function() {
return wc_country_select_params.i18n_no_matches;
},
formatAjaxError: function() {
errorLoading: function() {
return wc_country_select_params.i18n_ajax_error;
},
formatInputTooShort: function( input, min ) {
var number = min - input.length;
inputTooShort: function( args ) {
var remainingChars = args.minimum - args.input.length;
if ( 1 === number ) {
if ( 1 === remainingChars ) {
return wc_country_select_params.i18n_input_too_short_1;
}
return wc_country_select_params.i18n_input_too_short_n.replace( '%qty%', number );
return wc_country_select_params.i18n_input_too_short_n.replace( '%qty%', remainingChars );
},
formatInputTooLong: function( input, max ) {
var number = input.length - max;
inputTooLong: function( args ) {
var overChars = args.input.length - args.maximum;
if ( 1 === number ) {
if ( 1 === overChars ) {
return wc_country_select_params.i18n_input_too_long_1;
}
return wc_country_select_params.i18n_input_too_long_n.replace( '%qty%', number );
return wc_country_select_params.i18n_input_too_long_n.replace( '%qty%', overChars );
},
formatSelectionTooBig: function( limit ) {
if ( 1 === limit ) {
maximumSelected: function( args ) {
if ( 1 === args.maximum ) {
return wc_country_select_params.i18n_selection_too_long_1;
}
return wc_country_select_params.i18n_selection_too_long_n.replace( '%qty%', limit );
return wc_country_select_params.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
},
formatLoadMore: function() {
loadingMore: function() {
return wc_country_select_params.i18n_load_more;
},
formatSearching: function() {
searching: function() {
return wc_country_select_params.i18n_searching;
}
};
return formatString;
var language = { 'language' : formatString };
return language;
}
// Select2 Enhancement if it exists

View File

@ -1 +1 @@
jQuery(function(a){function b(){var a={formatMatches:function(a){return 1===a?wc_country_select_params.i18n_matches_1:wc_country_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_country_select_params.i18n_no_matches},formatAjaxError:function(){return wc_country_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_country_select_params.i18n_load_more},formatSearching:function(){return wc_country_select_params.i18n_searching}};return a}if("undefined"==typeof wc_country_select_params)return!1;if(a().select2){var c=function(){a("select.country_select:visible, select.state_select:visible").each(function(){var c=a.extend({placeholderOption:"first",width:"100%"},b());a(this).select2(c)})};c(),a(document.body).bind("country_to_state_changed",function(){c()})}var d=wc_country_select_params.countries.replace(/&quot;/g,'"'),e=a.parseJSON(d);a(document.body).on("change","select.country_to_state, input.country_to_state",function(){var b=a(this).closest(".woocommerce-billing-fields, .woocommerce-shipping-fields, .woocommerce-shipping-calculator");b.length||(b=a(this).closest(".form-row").parent());var c=a(this).val(),d=b.find("#billing_state, #shipping_state, #calc_shipping_state"),f=d.parent(),g=d.attr("name"),h=d.attr("id"),i=d.val(),j=d.attr("placeholder")||d.attr("data-placeholder")||"";if(e[c])if(a.isEmptyObject(e[c]))d.parent().hide().find(".select2-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+g+'" id="'+h+'" value="" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[c,b]);else{var k="",l=e[c];for(var m in l)l.hasOwnProperty(m)&&(k=k+'<option value="'+m+'">'+l[m]+"</option>");d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+g+'" id="'+h+'" class="state_select" data-placeholder="'+j+'"></select>'),d=b.find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+k),d.val(i).change(),a(document.body).trigger("country_to_state_changed",[c,b])}else d.is("select")?(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[c,b])):d.is('input[type="hidden"]')&&(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[c,b]));a(document.body).trigger("country_to_state_changing",[c,b])}),a(function(){a(":input.country_to_state").change()})});
jQuery(function(a){function b(){var a={noResults:function(){return wc_country_select_params.i18n_no_matches},errorLoading:function(){return wc_country_select_params.i18n_ajax_error},inputTooShort:function(a){var b=a.minimum-a.input.length;return 1===b?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",b)},inputTooLong:function(a){var b=a.input.length-a.maximum;return 1===b?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",b)},maximumSelected:function(a){return 1===a.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",a.maximum)},loadingMore:function(){return wc_country_select_params.i18n_load_more},searching:function(){return wc_country_select_params.i18n_searching}},b={language:a};return b}if("undefined"==typeof wc_country_select_params)return!1;if(a().select2){var c=function(){a("select.country_select:visible, select.state_select:visible").each(function(){var c=a.extend({placeholderOption:"first",width:"100%"},b());a(this).select2(c)})};c(),a(document.body).bind("country_to_state_changed",function(){c()})}var d=wc_country_select_params.countries.replace(/&quot;/g,'"'),e=a.parseJSON(d);a(document.body).on("change","select.country_to_state, input.country_to_state",function(){var b=a(this).closest(".woocommerce-billing-fields, .woocommerce-shipping-fields, .woocommerce-shipping-calculator");b.length||(b=a(this).closest(".form-row").parent());var c=a(this).val(),d=b.find("#billing_state, #shipping_state, #calc_shipping_state"),f=d.parent(),g=d.attr("name"),h=d.attr("id"),i=d.val(),j=d.attr("placeholder")||d.attr("data-placeholder")||"";if(e[c])if(a.isEmptyObject(e[c]))d.parent().hide().find(".select2-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+g+'" id="'+h+'" value="" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[c,b]);else{var k="",l=e[c];for(var m in l)l.hasOwnProperty(m)&&(k=k+'<option value="'+m+'">'+l[m]+"</option>");d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+g+'" id="'+h+'" class="state_select" data-placeholder="'+j+'"></select>'),d=b.find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+k),d.val(i).change(),a(document.body).trigger("country_to_state_changed",[c,b])}else d.is("select")?(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[c,b])):d.is('input[type="hidden"]')&&(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[c,b]));a(document.body).trigger("country_to_state_changing",[c,b])}),a(function(){a(":input.country_to_state").change()})});

View File

@ -124,7 +124,23 @@ jQuery( function( $ ) {
controlNav: wc_single_product_params.flexslider.controlNav,
slideshow: wc_single_product_params.flexslider.slideshow,
animationSpeed: wc_single_product_params.flexslider.animationSpeed,
animationLoop: false // Breaks photoswipe pagination if true. It's hard disabled because we don't need it anyway (no next/prev enabled in flex).
animationLoop: wc_single_product_params.flexslider.animationLoop, // Breaks photoswipe pagination if true.
start: function() {
var $images = $( '.woocommerce-product-gallery__image' );
var largest_height = 0;
$images.each( function() {
var height = $( this ).height();
if ( height > largest_height ) {
largest_height = height;
}
});
$images.each( function() {
$( this ).css( 'min-height', largest_height );
});
}
});
},

View File

@ -1 +1 @@
jQuery(function(a){if("undefined"==typeof wc_single_product_params)return!1;a("body").on("init",".wc-tabs-wrapper, .woocommerce-tabs",function(){a(".wc-tab, .woocommerce-tabs .panel:not(.panel .panel)").hide();var b=window.location.hash,c=window.location.href,d=a(this).find(".wc-tabs, ul.tabs").first();b.toLowerCase().indexOf("comment-")>=0||"#reviews"===b||"#tab-reviews"===b?d.find("li.reviews_tab a").click():c.indexOf("comment-page-")>0||c.indexOf("cpage=")>0?d.find("li.reviews_tab a").click():d.find("li:first a").click()}).on("click",".wc-tabs li a, ul.tabs li a",function(b){b.preventDefault();var c=a(this),d=c.closest(".wc-tabs-wrapper, .woocommerce-tabs"),e=d.find(".wc-tabs, ul.tabs");e.find("li").removeClass("active"),d.find(".wc-tab, .panel:not(.panel .panel)").hide(),c.closest("li").addClass("active"),d.find(c.attr("href")).show()}).on("click","a.woocommerce-review-link",function(){return a(".reviews_tab a").click(),!0}).on("init","#rating",function(){a("#rating").hide().before('<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2" href="#">2</a><a class="star-3" href="#">3</a><a class="star-4" href="#">4</a><a class="star-5" href="#">5</a></span></p>')}).on("click","#respond p.stars a",function(){var b=a(this),c=a(this).closest("#respond").find("#rating"),d=a(this).closest(".stars");return c.val(b.text()),b.siblings("a").removeClass("active"),b.addClass("active"),d.addClass("selected"),!1}).on("click","#respond #submit",function(){var b=a(this).closest("#respond").find("#rating"),c=b.val();if(b.length>0&&!c&&"yes"===wc_single_product_params.review_rating_required)return window.alert(wc_single_product_params.i18n_required_rating_text),!1}).on("woocommerce_init_gallery",function(){a.isFunction(a.fn.zoom)&&b.init_zoom()}),a(".wc-tabs-wrapper, .woocommerce-tabs, #rating").trigger("init");var b={init:function(){a.isFunction(a.fn.flexslider)&&this.init_flexslider(),a.isFunction(a.fn.zoom)&&this.init_zoom(),"undefined"!=typeof PhotoSwipe&&(this.init_photoswipe(),a(document).on("click",".woocommerce-product-gallery__trigger",this.trigger_photoswipe))},is_touch_device:function(){return"ontouchstart"in window||navigator.maxTouchPoints},init_flexslider:function(){a(".woocommerce-product-gallery").flexslider({selector:".woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image",animation:wc_single_product_params.flexslider.animation,smoothHeight:wc_single_product_params.flexslider.smoothHeight,directionNav:wc_single_product_params.flexslider.directionNav,controlNav:wc_single_product_params.flexslider.controlNav,slideshow:wc_single_product_params.flexslider.slideshow,animationSpeed:wc_single_product_params.flexslider.animationSpeed,animationLoop:!1})},init_zoom:function(){a(".woocommerce-product-gallery__image img").attr("width")>a(".woocommerce-product-gallery").width()&&(a(".woocommerce-product-gallery__image").trigger("zoom.destroy"),a(".woocommerce-product-gallery__image").zoom({touch:!1}))},get_gallery_items:function(){var b=a(".woocommerce-product-gallery__wrapper").children(),c=[],d=b.filter(".flex-active-slide").index();return b.length>0&&b.each(function(b,d){var e=a(d).find("img"),f=e.attr("data-large-image"),g=e.attr("data-large-image-width"),h=e.attr("data-large-image-height"),i={src:f,w:g,h:h,title:e.attr("title")};c.push(i)}),{index:d,items:c}},init_photoswipe:function(){a(".woocommerce-product-gallery--with-images").prepend('<a href="#" class="woocommerce-product-gallery__trigger">🔍</a>')},trigger_photoswipe:function(c){c.preventDefault();var d=a(".pswp")[0],e=b.get_gallery_items(),f={index:e.index,shareEl:!1,closeOnScroll:!1,history:!1,hideAnimationDuration:0,showAnimationDuration:0},g=new PhotoSwipe(d,PhotoSwipeUI_Default,e.items,f);g.init()}};b.init()});
jQuery(function(a){if("undefined"==typeof wc_single_product_params)return!1;a("body").on("init",".wc-tabs-wrapper, .woocommerce-tabs",function(){a(".wc-tab, .woocommerce-tabs .panel:not(.panel .panel)").hide();var b=window.location.hash,c=window.location.href,d=a(this).find(".wc-tabs, ul.tabs").first();b.toLowerCase().indexOf("comment-")>=0||"#reviews"===b||"#tab-reviews"===b?d.find("li.reviews_tab a").click():c.indexOf("comment-page-")>0||c.indexOf("cpage=")>0?d.find("li.reviews_tab a").click():d.find("li:first a").click()}).on("click",".wc-tabs li a, ul.tabs li a",function(b){b.preventDefault();var c=a(this),d=c.closest(".wc-tabs-wrapper, .woocommerce-tabs"),e=d.find(".wc-tabs, ul.tabs");e.find("li").removeClass("active"),d.find(".wc-tab, .panel:not(.panel .panel)").hide(),c.closest("li").addClass("active"),d.find(c.attr("href")).show()}).on("click","a.woocommerce-review-link",function(){return a(".reviews_tab a").click(),!0}).on("init","#rating",function(){a("#rating").hide().before('<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2" href="#">2</a><a class="star-3" href="#">3</a><a class="star-4" href="#">4</a><a class="star-5" href="#">5</a></span></p>')}).on("click","#respond p.stars a",function(){var b=a(this),c=a(this).closest("#respond").find("#rating"),d=a(this).closest(".stars");return c.val(b.text()),b.siblings("a").removeClass("active"),b.addClass("active"),d.addClass("selected"),!1}).on("click","#respond #submit",function(){var b=a(this).closest("#respond").find("#rating"),c=b.val();if(b.length>0&&!c&&"yes"===wc_single_product_params.review_rating_required)return window.alert(wc_single_product_params.i18n_required_rating_text),!1}).on("woocommerce_init_gallery",function(){a.isFunction(a.fn.zoom)&&b.init_zoom()}),a(".wc-tabs-wrapper, .woocommerce-tabs, #rating").trigger("init");var b={init:function(){a.isFunction(a.fn.flexslider)&&this.init_flexslider(),a.isFunction(a.fn.zoom)&&this.init_zoom(),"undefined"!=typeof PhotoSwipe&&(this.init_photoswipe(),a(document).on("click",".woocommerce-product-gallery__trigger",this.trigger_photoswipe))},is_touch_device:function(){return"ontouchstart"in window||navigator.maxTouchPoints},init_flexslider:function(){a(".woocommerce-product-gallery").flexslider({selector:".woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image",animation:wc_single_product_params.flexslider.animation,smoothHeight:wc_single_product_params.flexslider.smoothHeight,directionNav:wc_single_product_params.flexslider.directionNav,controlNav:wc_single_product_params.flexslider.controlNav,slideshow:wc_single_product_params.flexslider.slideshow,animationSpeed:wc_single_product_params.flexslider.animationSpeed,animationLoop:wc_single_product_params.flexslider.animationLoop,start:function(){var b=a(".woocommerce-product-gallery__image"),c=0;b.each(function(){var b=a(this).height();b>c&&(c=b)}),b.each(function(){a(this).css("min-height",c)})}})},init_zoom:function(){a(".woocommerce-product-gallery__image img").attr("width")>a(".woocommerce-product-gallery").width()&&(a(".woocommerce-product-gallery__image").trigger("zoom.destroy"),a(".woocommerce-product-gallery__image").zoom({touch:!1}))},get_gallery_items:function(){var b=a(".woocommerce-product-gallery__wrapper").children(),c=[],d=b.filter(".flex-active-slide").index();return b.length>0&&b.each(function(b,d){var e=a(d).find("img"),f=e.attr("data-large-image"),g=e.attr("data-large-image-width"),h=e.attr("data-large-image-height"),i={src:f,w:g,h:h,title:e.attr("title")};c.push(i)}),{index:d,items:c}},init_photoswipe:function(){a(".woocommerce-product-gallery--with-images").prepend('<a href="#" class="woocommerce-product-gallery__trigger">🔍</a>')},trigger_photoswipe:function(c){c.preventDefault();var d=a(".pswp")[0],e=b.get_gallery_items(),f={index:e.index,shareEl:!1,closeOnScroll:!1,history:!1,hideAnimationDuration:0,showAnimationDuration:0},g=new PhotoSwipe(d,PhotoSwipeUI_Default,e.items,f);g.init()}};b.init()});

View File

@ -1,5 +1,5 @@
/*!
Zoom 1.7.15
Zoom 1.7.18
license: MIT
http://www.jacklmoore.com/zoom
*/
@ -30,9 +30,8 @@
$source = $(source);
// The parent element needs positioning so that the zoomed element can be correctly positioned within.
$target.css('position', /(absolute|fixed)/.test(position) ? position : 'relative');
$target.css('overflow', 'hidden');
target.style.position = /(absolute|fixed)/.test(position) ? position : 'relative';
target.style.overflow = 'hidden';
img.style.width = img.style.height = '';
$(img)
@ -55,7 +54,7 @@
targetWidth = $target.outerWidth();
targetHeight = $target.outerHeight();
if (source === $target[0]) {
if (source === target) {
sourceWidth = targetWidth;
sourceHeight = targetHeight;
} else {
@ -86,41 +85,34 @@
var
settings = $.extend({}, defaults, options || {}),
//target will display the zoomed image
target = settings.target || this,
target = settings.target && $(settings.target)[0] || this,
//source will provide zoom location info (thumbnail)
source = this,
$source = $(source),
$target = $(target),
img = document.createElement('img'),
$img = $(img),
mousemove = 'mousemove.zoom',
clicked = false,
touched = false,
$urlElement;
touched = false;
// If a url wasn't specified, look for an image element.
if (!settings.url) {
$urlElement = $source.find('img');
if ($urlElement[0]) {
settings.url = $urlElement.data('src') || $urlElement.attr('src');
var srcElement = source.querySelector('img');
if (srcElement) {
settings.url = srcElement.getAttribute('data-src') || srcElement.currentSrc || srcElement.src;
}
if (!settings.url) {
return;
}
}
(function(){
var position = $target.css('position');
var overflow = $target.css('overflow');
$source.one('zoom.destroy', function(){
$source.off(".zoom");
$target.css('position', position);
$target.css('overflow', overflow);
$img.remove();
});
}());
$source.one('zoom.destroy', function(position, overflow){
$source.off(".zoom");
target.style.position = position;
target.style.overflow = overflow;
img.onload = null;
$img.remove();
}.bind(this, target.style.position, target.style.overflow));
img.onload = function () {
var zoom = $.zoom(target, source, img, settings.magnify);
@ -228,7 +220,7 @@
}
});
}
if ($.isFunction(settings.callback)) {
settings.callback.call(img);
}

View File

@ -1,6 +1,6 @@
/*!
Zoom 1.7.15
Zoom 1.7.18
license: MIT
http://www.jacklmoore.com/zoom
*/
!function(a){var b={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};a.zoom=function(b,c,d,e){var f,g,h,i,j,k,l,m=a(b),n=m.css("position"),o=a(c);return m.css("position",/(absolute|fixed)/.test(n)?n:"relative"),m.css("overflow","hidden"),d.style.width=d.style.height="",a(d).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:d.width*e,height:d.height*e,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(b),{init:function(){g=m.outerWidth(),f=m.outerHeight(),c===m[0]?(i=g,h=f):(i=o.outerWidth(),h=o.outerHeight()),j=(d.width-g)/i,k=(d.height-f)/h,l=o.offset()},move:function(a){var b=a.pageX-l.left,c=a.pageY-l.top;c=Math.max(Math.min(c,h),0),b=Math.max(Math.min(b,i),0),d.style.left=b*-j+"px",d.style.top=c*-k+"px"}}},a.fn.zoom=function(c){return this.each(function(){var d,e=a.extend({},b,c||{}),f=e.target||this,g=this,h=a(g),i=a(f),j=document.createElement("img"),k=a(j),l="mousemove.zoom",m=!1,n=!1;(e.url||(d=h.find("img"),d[0]&&(e.url=d.data("src")||d.attr("src")),e.url))&&(!function(){var a=i.css("position"),b=i.css("overflow");h.one("zoom.destroy",function(){h.off(".zoom"),i.css("position",a),i.css("overflow",b),k.remove()})}(),j.onload=function(){function b(b){d.init(),d.move(b),k.stop().fadeTo(a.support.opacity?e.duration:0,1,!!a.isFunction(e.onZoomIn)&&e.onZoomIn.call(j))}function c(){k.stop().fadeTo(e.duration,0,!!a.isFunction(e.onZoomOut)&&e.onZoomOut.call(j))}var d=a.zoom(f,g,j,e.magnify);"grab"===e.on?h.on("mousedown.zoom",function(e){1===e.which&&(a(document).one("mouseup.zoom",function(){c(),a(document).off(l,d.move)}),b(e),a(document).on(l,d.move),e.preventDefault())}):"click"===e.on?h.on("click.zoom",function(e){return m?void 0:(m=!0,b(e),a(document).on(l,d.move),a(document).one("click.zoom",function(){c(),m=!1,a(document).off(l,d.move)}),!1)}):"toggle"===e.on?h.on("click.zoom",function(a){m?c():b(a),m=!m}):"mouseover"===e.on&&(d.init(),h.on("mouseenter.zoom",b).on("mouseleave.zoom",c).on(l,d.move)),e.touch&&h.on("touchstart.zoom",function(a){a.preventDefault(),n?(n=!1,c()):(n=!0,b(a.originalEvent.touches[0]||a.originalEvent.changedTouches[0]))}).on("touchmove.zoom",function(a){a.preventDefault(),d.move(a.originalEvent.touches[0]||a.originalEvent.changedTouches[0])}).on("touchend.zoom",function(a){a.preventDefault(),n&&(n=!1,c())}),a.isFunction(e.callback)&&e.callback.call(j)},j.src=e.url)})},a.fn.zoom.defaults=b}(window.jQuery);
(function(o){var t={url:!1,callback:!1,target:!1,duration:120,on:"mouseover",touch:!0,onZoomIn:!1,onZoomOut:!1,magnify:1};o.zoom=function(t,n,e,i){var u,c,a,r,m,l,s,f=o(t),h=f.css("position"),d=o(n);return t.style.position=/(absolute|fixed)/.test(h)?h:"relative",t.style.overflow="hidden",e.style.width=e.style.height="",o(e).addClass("zoomImg").css({position:"absolute",top:0,left:0,opacity:0,width:e.width*i,height:e.height*i,border:"none",maxWidth:"none",maxHeight:"none"}).appendTo(t),{init:function(){c=f.outerWidth(),u=f.outerHeight(),n===t?(r=c,a=u):(r=d.outerWidth(),a=d.outerHeight()),m=(e.width-c)/r,l=(e.height-u)/a,s=d.offset()},move:function(o){var t=o.pageX-s.left,n=o.pageY-s.top;n=Math.max(Math.min(n,a),0),t=Math.max(Math.min(t,r),0),e.style.left=t*-m+"px",e.style.top=n*-l+"px"}}},o.fn.zoom=function(n){return this.each(function(){var e=o.extend({},t,n||{}),i=e.target&&o(e.target)[0]||this,u=this,c=o(u),a=document.createElement("img"),r=o(a),m="mousemove.zoom",l=!1,s=!1;if(!e.url){var f=u.querySelector("img");if(f&&(e.url=f.getAttribute("data-src")||f.currentSrc||f.src),!e.url)return}c.one("zoom.destroy",function(o,t){c.off(".zoom"),i.style.position=o,i.style.overflow=t,a.onload=null,r.remove()}.bind(this,i.style.position,i.style.overflow)),a.onload=function(){function t(t){f.init(),f.move(t),r.stop().fadeTo(o.support.opacity?e.duration:0,1,o.isFunction(e.onZoomIn)?e.onZoomIn.call(a):!1)}function n(){r.stop().fadeTo(e.duration,0,o.isFunction(e.onZoomOut)?e.onZoomOut.call(a):!1)}var f=o.zoom(i,u,a,e.magnify);"grab"===e.on?c.on("mousedown.zoom",function(e){1===e.which&&(o(document).one("mouseup.zoom",function(){n(),o(document).off(m,f.move)}),t(e),o(document).on(m,f.move),e.preventDefault())}):"click"===e.on?c.on("click.zoom",function(e){return l?void 0:(l=!0,t(e),o(document).on(m,f.move),o(document).one("click.zoom",function(){n(),l=!1,o(document).off(m,f.move)}),!1)}):"toggle"===e.on?c.on("click.zoom",function(o){l?n():t(o),l=!l}):"mouseover"===e.on&&(f.init(),c.on("mouseenter.zoom",t).on("mouseleave.zoom",n).on(m,f.move)),e.touch&&c.on("touchstart.zoom",function(o){o.preventDefault(),s?(s=!1,n()):(s=!0,t(o.originalEvent.touches[0]||o.originalEvent.changedTouches[0]))}).on("touchmove.zoom",function(o){o.preventDefault(),f.move(o.originalEvent.touches[0]||o.originalEvent.changedTouches[0])}).on("touchend.zoom",function(o){o.preventDefault(),s&&(s=!1,n())}),o.isFunction(e.callback)&&e.callback.call(a)},a.src=e.url})},o.fn.zoom.defaults=t})(window.jQuery);

View File

@ -5,7 +5,7 @@
"type": "wordpress-plugin",
"license": "GPL-2.0+",
"require": {
"composer/installers": "~1.0"
"composer/installers": "~1.2"
},
"require-dev": {
"squizlabs/php_codesniffer": "*",

File diff suppressed because it is too large Load Diff

View File

@ -254,6 +254,26 @@ return array(
),
),
),
'FI' => array(
'currency_code' => 'EUR',
'currency_pos' => 'right_space',
'thousand_sep' => ' ',
'decimal_sep' => ',',
'num_decimals' => 2,
'weight_unit' => 'kg',
'dimension_unit' => 'cm',
'tax_rates' => array(
'' => array(
array(
'country' => 'FI',
'state' => '',
'rate' => '24.0000',
'name' => 'ALV',
'shipping' => true
)
)
)
),
'FR' => array(
'currency_code' => 'EUR',
'currency_pos' => 'right',

View File

@ -17,30 +17,40 @@ abstract class WC_Data {
/**
* ID for this object.
*
* @since 2.7.0
* @var int
*/
protected $id = 0;
/**
* Core data for this object. Name value pairs (name + default value).
*
* @since 2.7.0
* @var array
*/
protected $data = array();
/**
* Core data changes for this object.
*
* @since 2.7.0
* @var array
*/
protected $changes = array();
/**
* This is false until the object is read from the DB.
*
* @since 2.7.0
* @var bool
*/
protected $object_read = false;
/**
* This is the name of this object type.
*
* @since 2.7.0
* @var string
*/
protected $object_type = 'data';
@ -49,18 +59,24 @@ abstract class WC_Data {
* Extra data for this object. Name value pairs (name + default value).
* Used as a standard way for sub classes (like product types) to add
* additional information to an inherited class.
*
* @since 2.7.0
* @var array
*/
protected $extra_data = array();
/**
* Set to _data on construct so we can track and reset data if needed.
*
* @since 2.7.0
* @var array
*/
protected $default_data = array();
/**
* Contains a reference to the data store for this class.
*
* @since 2.7.0
* @var object
*/
protected $data_store;
@ -68,28 +84,36 @@ abstract class WC_Data {
/**
* Stores meta in cache for future reads.
* A group must be set to to enable caching.
*
* @since 2.7.0
* @var string
*/
protected $cache_group = '';
/**
* Stores additonal meta data.
*
* @since 2.7.0
* @var array
*/
protected $meta_data = null;
/**
* Default constructor.
*
* @param int|object|array $read ID to load from the DB (optional) or already queried data.
*/
public function __construct( $read = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
$this->default_data = $this->data;
}
/**
* Get the data store.
*
* @since 2.7.0
* @since 2.7.0
* @return object
*/
public function get_data_store() {
@ -98,6 +122,8 @@ abstract class WC_Data {
/**
* Returns the unique ID for this object.
*
* @since 2.6.0
* @return int
*/
public function get_id() {
@ -107,6 +133,7 @@ abstract class WC_Data {
/**
* Delete an object, set the ID to 0, and return result.
*
* @since 2.6.0
* @param bool $force_delete
* @return bool result
*/
@ -122,6 +149,7 @@ abstract class WC_Data {
/**
* Save should create or update based on object existance.
*
* @since 2.6.0
* @return int
*/
public function save() {
@ -140,6 +168,8 @@ abstract class WC_Data {
/**
* Change data to JSON format.
*
* @since 2.6.0
* @return string Data in JSON format.
*/
public function __toString() {
@ -148,6 +178,8 @@ abstract class WC_Data {
/**
* Returns all data for this object.
*
* @since 2.6.0
* @return array
*/
public function get_data() {
@ -157,7 +189,7 @@ abstract class WC_Data {
/**
* Returns array of expected data keys for this object.
*
* @since 2.7.0
* @since 2.7.0
* @return array
*/
public function get_data_keys() {
@ -167,7 +199,7 @@ abstract class WC_Data {
/**
* Returns all "extra" data keys for an object (for sub objects like product types).
*
* @since 2.7.0
* @since 2.7.0
* @return array
*/
public function get_extra_data_keys() {
@ -176,6 +208,8 @@ abstract class WC_Data {
/**
* Filter null meta values from array.
*
* @since 2.7.0
* @return bool
*/
protected function filter_null_meta( $meta ) {
@ -184,6 +218,7 @@ abstract class WC_Data {
/**
* Get All Meta Data.
*
* @since 2.6.0
* @return array
*/
@ -194,6 +229,7 @@ abstract class WC_Data {
/**
* Get Meta Data by Key.
*
* @since 2.6.0
* @param string $key
* @param bool $single return first found meta with key, or all with $key
@ -222,6 +258,7 @@ abstract class WC_Data {
/**
* Set all meta data from array.
*
* @since 2.6.0
* @param array $data Key/Value pairs
*/
@ -243,6 +280,7 @@ abstract class WC_Data {
/**
* Add meta data.
*
* @since 2.6.0
* @param string $key Meta key
* @param string $value Meta value
@ -261,7 +299,8 @@ abstract class WC_Data {
/**
* Update meta data by key or ID, if provided.
* @since 2.6.0
*
* @since 2.6.0
* @param string $key
* @param string $value
* @param int $meta_id
@ -281,6 +320,7 @@ abstract class WC_Data {
/**
* Delete meta data.
*
* @since 2.6.0
* @param array $key Meta key
*/
@ -295,6 +335,7 @@ abstract class WC_Data {
/**
* Delete meta data.
*
* @since 2.6.0
* @param int $mid Meta ID
*/
@ -371,6 +412,7 @@ abstract class WC_Data {
/**
* Update Meta Data in the database.
*
* @since 2.6.0
*/
public function save_meta_data() {
@ -399,6 +441,8 @@ abstract class WC_Data {
/**
* Set ID.
*
* @since 2.7.0
* @param int $id
*/
public function set_id( $id ) {
@ -407,6 +451,8 @@ abstract class WC_Data {
/**
* Set all props to default values.
*
* @since 2.7.0
*/
public function set_defaults() {
$this->data = $this->default_data;
@ -416,6 +462,8 @@ abstract class WC_Data {
/**
* Set object read property.
*
* @since 2.7.0
* @param boolean $read
*/
public function set_object_read( $read = true ) {
@ -424,6 +472,8 @@ abstract class WC_Data {
/**
* Get object read property.
*
* @since 2.7.0
* @return boolean
*/
public function get_object_read() {
@ -434,7 +484,8 @@ abstract class WC_Data {
* Set a collection of props in one go, collect any errors, and return the result.
* Only sets using public methods.
*
* @param array $props Key value pairs to set. Key is the prop and should map to a setter function name.
* @since 2.7.0
* @param array $props Key value pairs to set. Key is the prop and should map to a setter function name.
* @return WP_Error|bool
*/
public function set_props( $props, $context = 'set' ) {
@ -510,7 +561,7 @@ abstract class WC_Data {
* @return string
*/
protected function get_hook_prefix() {
return 'woocommerce_get_' . $this->object_type . '_';
return 'woocommerce_' . $this->object_type . '_get_';
}
/**
@ -539,11 +590,15 @@ abstract class WC_Data {
/**
* When invalid data is found, throw an exception unless reading from the DB.
* @param string $error_code Error code.
* @param string $error_message Error message.
*
* @throws WC_Data_Exception
* @since 2.7.0
* @param string $code Error code.
* @param string $message Error message.
* @param int $http_status_code HTTP status code.
* @param array $data Extra error data.
*/
protected function error( $error_code, $error_message ) {
throw new WC_Data_Exception( $error_code, $error_message );
protected function error( $code, $message, $http_status_code = 400, $data = array() ) {
throw new WC_Data_Exception( $code, $message, $http_status_code, $data );
}
}

View File

@ -25,7 +25,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function add_coupon( $code = array(), $discount = 0, $discount_tax = 0 ) {
wc_deprecated_function( 'WC_Order::add_coupon', '2.7', 'Create new WC_Order_Item_Coupon object and add to order with WC_Order::add_item()' );
wc_deprecated_function( 'WC_Order::add_coupon', '2.7', 'a new WC_Order_Item_Coupon object and add to order with WC_Order::add_item()' );
$item = new WC_Order_Item_Coupon();
$item->set_props( array(
@ -36,7 +36,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
) );
$item->save();
$this->add_item( $item );
wc_do_deprecated_action( 'woocommerce_order_add_coupon', array( $this->get_id(), $item->get_id(), $code, $discount, $discount_tax ), '2.7', 'Use woocommerce_new_order_item action instead.' );
wc_do_deprecated_action( 'woocommerce_order_add_coupon', array( $this->get_id(), $item->get_id(), $code, $discount, $discount_tax ), '2.7', 'woocommerce_new_order_item action instead.' );
return $item->get_id();
}
@ -49,7 +49,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function add_tax( $tax_rate_id, $tax_amount = 0, $shipping_tax_amount = 0 ) {
wc_deprecated_function( 'WC_Order::add_tax', '2.7', 'Create new WC_Order_Item_Tax object and add to order with WC_Order::add_item()' );
wc_deprecated_function( 'WC_Order::add_tax', '2.7', 'a new WC_Order_Item_Tax object and add to order with WC_Order::add_item()' );
$item = new WC_Order_Item_Tax();
$item->set_props( array(
@ -61,7 +61,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
$item->set_order_id( $this->get_id() );
$item->save();
$this->add_item( $item );
wc_do_deprecated_action( 'woocommerce_order_add_tax', array( $this->get_id(), $item->get_id(), $tax_rate_id, $tax_amount, $shipping_tax_amount ), '2.7', 'Use woocommerce_new_order_item action instead.' );
wc_do_deprecated_action( 'woocommerce_order_add_tax', array( $this->get_id(), $item->get_id(), $tax_rate_id, $tax_amount, $shipping_tax_amount ), '2.7', 'woocommerce_new_order_item action instead.' );
return $item->get_id();
}
@ -72,7 +72,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function add_shipping( $shipping_rate ) {
wc_deprecated_function( 'WC_Order::add_shipping', '2.7', 'Create new WC_Order_Item_Shipping object and add to order with WC_Order::add_item()' );
wc_deprecated_function( 'WC_Order::add_shipping', '2.7', 'a new WC_Order_Item_Shipping object and add to order with WC_Order::add_item()' );
$item = new WC_Order_Item_Shipping();
$item->set_props( array(
@ -80,12 +80,14 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
'method_id' => $shipping_rate->id,
'total' => wc_format_decimal( $shipping_rate->cost ),
'taxes' => $shipping_rate->taxes,
'meta_data' => $shipping_rate->get_meta_data(),
'order_id' => $this->get_id(),
) );
foreach ( $shipping_rate->get_meta_data() as $key => $value ) {
$item->add_meta_data( $key, $value, true );
}
$item->save();
$this->add_item( $item );
wc_do_deprecated_action( 'woocommerce_order_add_shipping', array( $this->get_id(), $item->get_id(), $shipping_rate ), '2.7', 'Use woocommerce_new_order_item action instead.' );
wc_do_deprecated_action( 'woocommerce_order_add_shipping', array( $this->get_id(), $item->get_id(), $shipping_rate ), '2.7', 'woocommerce_new_order_item action instead.' );
return $item->get_id();
}
@ -97,7 +99,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function add_fee( $fee ) {
wc_deprecated_function( 'WC_Order::add_fee', '2.7', 'Create new WC_Order_Item_Fee object and add to order with WC_Order::add_item()' );
wc_deprecated_function( 'WC_Order::add_fee', '2.7', 'a new WC_Order_Item_Fee object and add to order with WC_Order::add_item()' );
$item = new WC_Order_Item_Fee();
$item->set_props( array(
@ -112,7 +114,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
) );
$item->save();
$this->add_item( $item );
wc_do_deprecated_action( 'woocommerce_order_add_fee', array( $this->get_id(), $item->get_id(), $fee ), '2.7', 'Use woocommerce_new_order_item action instead.' );
wc_do_deprecated_action( 'woocommerce_order_add_fee', array( $this->get_id(), $item->get_id(), $fee ), '2.7', 'woocommerce_new_order_item action instead.' );
return $item->get_id();
}
@ -128,7 +130,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function update_product( $item, $product, $args ) {
wc_deprecated_function( 'WC_Order::update_product', '2.7', 'Interact with WC_Order_Item_Product class' );
wc_deprecated_function( 'WC_Order::update_product', '2.7', 'an interaction with the WC_Order_Item_Product class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
@ -177,7 +179,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function update_coupon( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_coupon', '2.7', 'Interact with WC_Order_Item_Coupon class' );
wc_deprecated_function( 'WC_Order::update_coupon', '2.7', 'an interaction with the WC_Order_Item_Coupon class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
@ -216,7 +218,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function update_shipping( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_shipping', '2.7', 'Interact with WC_Order_Item_Shipping class' );
wc_deprecated_function( 'WC_Order::update_shipping', '2.7', 'an interaction with the WC_Order_Item_Shipping class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
@ -253,7 +255,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function update_fee( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_fee', '2.7', 'Interact with WC_Order_Item_Fee class' );
wc_deprecated_function( 'WC_Order::update_fee', '2.7', 'an interaction with the WC_Order_Item_Fee class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
@ -284,7 +286,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @throws WC_Data_Exception
*/
public function update_tax( $item, $args ) {
wc_deprecated_function( 'WC_Order::update_tax', '2.7', 'Interact with WC_Order_Item_Tax class' );
wc_deprecated_function( 'WC_Order::update_tax', '2.7', 'an interaction with the WC_Order_Item_Tax class' );
if ( is_numeric( $item ) ) {
$item = $this->get_item( $item );
}
@ -400,13 +402,13 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '2.7' );
if ( 'completed_date' === $key ) {
return $this->get_date_completed();
return date( 'Y-m-d H:i:s', $this->get_date_completed() );
} elseif ( 'paid_date' === $key ) {
return $this->get_date_paid();
} elseif ( 'modified_date' === $key ) {
return $this->get_date_modified();
return date( 'Y-m-d H:i:s', $this->get_date_modified() );
} elseif ( 'order_date' === $key ) {
return $this->get_date_created();
return date( 'Y-m-d H:i:s', $this->get_date_created() );
} elseif ( 'id' === $key ) {
return $this->get_id();
} elseif ( 'post' === $key ) {
@ -426,7 +428,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
} elseif ( 'display_cart_ex_tax' === $key ) {
return 'excl' === get_option( 'woocommerce_tax_display_cart' );
} elseif ( 'cart_discount' === $key ) {
return $this->get_discount();
return $this->get_total_discount();
} elseif ( 'cart_discount_tax' === $key ) {
return $this->get_discount_tax();
} elseif ( 'order_tax' === $key ) {

View File

@ -22,7 +22,7 @@ abstract class WC_Legacy_Payment_Token extends WC_Data {
* @deprecated 2.7.0 - Init a token class with an ID.
*/
public function read( $token_id ) {
wc_deprecated_function( 'WC_Payment_Token::read', '2.7', 'Init a token class with an ID.' );
wc_deprecated_function( 'WC_Payment_Token::read', '2.7', 'a new token class initialized with an ID.' );
$this->set_id( $token_id );
$data_store = WC_Data_Store::load( 'payment-token' );
$data_store->read( $this );
@ -33,7 +33,7 @@ abstract class WC_Legacy_Payment_Token extends WC_Data {
* @deprecated 2.7.0 - Use ::save instead.
*/
public function update() {
wc_deprecated_function( 'WC_Payment_Token::update', '2.7', 'Use ::save instead.' );
wc_deprecated_function( 'WC_Payment_Token::update', '2.7', '::save instead.' );
$data_store = WC_Data_Store::load( 'payment-token' );
try {
$data_store->update( $this );
@ -47,7 +47,7 @@ abstract class WC_Legacy_Payment_Token extends WC_Data {
* @deprecated 2.7.0 - Use ::save instead.
*/
public function create() {
wc_deprecated_function( 'WC_Payment_Token::create', '2.7', 'Use ::save instead.' );
wc_deprecated_function( 'WC_Payment_Token::create', '2.7', '::save instead.' );
$data_store = WC_Data_Store::load( 'payment-token' );
try {
$data_store->create( $this );

View File

@ -417,7 +417,7 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
* @return bool
*/
public function has_default_attributes() {
wc_deprecated_function( 'WC_Product_Variable::has_default_attributes', '2.7', 'Check WC_Product::get_default_attributes directly' );
wc_deprecated_function( 'WC_Product_Variable::has_default_attributes', '2.7', 'a check against WC_Product::get_default_attributes directly' );
if ( ! $this->get_default_attributes() ) {
return true;
}
@ -431,7 +431,7 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
* @return int
*/
public function get_variation_id() {
wc_deprecated_function( 'WC_Product::get_variation_id', '2.7', 'WC_Product::get_id() will always be the variation ID if this is a variation.' );
wc_deprecated_function( 'WC_Product::get_variation_id', '2.7', 'WC_Product::get_id(). It will always be the variation ID if this is a variation.' );
return $this->get_id();
}
@ -453,7 +453,7 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
* @return boolean
*/
public function has_all_attributes_set() {
wc_deprecated_function( 'WC_Product::has_all_attributes_set', '2.7', 'Use array filter on get_variation_attributes for a quick solution.' );
wc_deprecated_function( 'WC_Product::has_all_attributes_set', '2.7', 'an array filter on get_variation_attributes for a quick solution.' );
$set = true;
// undefined attributes have null strings as array values
@ -484,7 +484,7 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
* @return int
*/
public function get_total_stock() {
wc_deprecated_function( 'WC_Product::get_total_stock', '2.7', 'Use get_stock_quantity on each child. Beware of performance issues in doing so.' );
wc_deprecated_function( 'WC_Product::get_total_stock', '2.7', 'get_stock_quantity on each child. Beware of performance issues in doing so.' );
if ( sizeof( $this->get_children() ) > 0 ) {
$total_stock = max( 0, $this->get_stock_quantity() );

View File

@ -11,20 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @category Abstract Class
* @author WooThemes
*/
abstract class WC_Log_Handler {
/**
* Handle a log entry.
*
* @param int $timestamp Log timestamp.
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
* @param string $message Log message.
* @param array $context Additional information for log handlers.
*
* @return bool False if value was not handled and true if value was handled.
*/
abstract public function handle( $timestamp, $level, $message, $context );
abstract class WC_Log_Handler implements WC_Log_Handler_Interface {
/**
* Formats a timestamp for use in log messages.

View File

@ -213,17 +213,17 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
switch ( $item_group ) {
case 'fee_lines' :
if ( isset( $item->legacy_fee, $item->legacy_fee_key ) ) {
wc_do_deprecated_action( 'woocommerce_add_order_fee_meta', array( $this->get_id(), $item_id, $item->legacy_fee, $item->legacy_fee_key ), '2.7', 'Use CRUD and woocommerce_checkout_create_order_fee_item action instead.' );
wc_do_deprecated_action( 'woocommerce_add_order_fee_meta', array( $this->get_id(), $item_id, $item->legacy_fee, $item->legacy_fee_key ), '2.7', 'CRUD and woocommerce_checkout_create_order_fee_item action instead' );
}
break;
case 'shipping_lines' :
if ( isset( $item->legacy_package_key ) ) {
wc_do_deprecated_action( 'woocommerce_add_shipping_order_item', array( $this->get_id(), $item_id, $item->legacy_package_key ), '2.7', 'Use CRUD woocommerce_checkout_create_order_shipping_item action instead.' );
wc_do_deprecated_action( 'woocommerce_add_shipping_order_item', array( $this->get_id(), $item_id, $item->legacy_package_key ), '2.7', 'CRUD woocommerce_checkout_create_order_shipping_item action instead' );
}
break;
case 'line_items' :
if ( isset( $item->legacy_values, $item->legacy_cart_item_key ) ) {
wc_do_deprecated_action( 'woocommerce_add_order_item_meta', array( $item_id, $item->legacy_values, $item->legacy_cart_item_key ), '2.7', 'Use CRUD and woocommerce_checkout_create_order_line_item action instead.' );
wc_do_deprecated_action( 'woocommerce_add_order_item_meta', array( $item_id, $item->legacy_values, $item->legacy_cart_item_key ), '2.7', 'CRUD and woocommerce_checkout_create_order_line_item action instead' );
}
break;
}
@ -447,6 +447,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
return apply_filters( 'woocommerce_order_get_tax_totals', $tax_totals, $this );
}
/**
* Get all valid statuses for this order
*
* @since 2.7.0
* @return array Internal status keys e.g. 'wc-processing'
*/
protected function get_valid_statuses() {
return array_keys( wc_get_order_statuses() );
}
/*
|--------------------------------------------------------------------------
| Setters
@ -484,14 +494,14 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
// Only allow valid new status
if ( ! in_array( 'wc-' . $new_status, array_keys( wc_get_order_statuses() ) ) ) {
if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) ) {
$new_status = 'pending';
}
$this->set_prop( 'status', $new_status );
// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
if ( $old_status && ! in_array( 'wc-' . $old_status, array_keys( wc_get_order_statuses() ) ) ) {
if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses() ) ) {
$old_status = 'pending';
}
@ -890,7 +900,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$item->set_order_id( $this->get_id() );
$item->save();
$this->add_item( $item );
wc_do_deprecated_action( 'woocommerce_order_add_product', array( $this->get_id(), $item->get_id(), $product, $qty, $args ), '2.7', 'Use woocommerce_new_order_item action instead.' );
wc_do_deprecated_action( 'woocommerce_order_add_product', array( $this->get_id(), $item->get_id(), $product, $qty, $args ), '2.7', 'woocommerce_new_order_item action instead' );
return $item->get_id();
}
@ -1038,11 +1048,10 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
// Inherit tax class from items
if ( 'inherit' === $shipping_tax_class ) {
$tax_rates = array();
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_class_slugs() );
$found_tax_classes = $this->get_items_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'],

View File

@ -145,23 +145,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
| Methods for getting data from the product object.
*/
/**
* Get all class data in array format.
* @since 2.7.0
* @return array
*/
public function get_data() {
return array_merge(
array(
'id' => $this->get_id(),
),
$this->data,
array(
'meta_data' => $this->get_meta_data(),
)
);
}
/**
* Get product name.
*
@ -804,7 +787,9 @@ class WC_Product extends WC_Abstract_Legacy_Product {
public function set_sku( $sku ) {
$sku = (string) $sku;
if ( $this->get_object_read() && ! empty( $sku ) && ! wc_product_has_unique_sku( $this->get_id(), $sku ) ) {
$this->error( 'product_invalid_sku', __( 'Invalid or duplicated SKU.', 'woocommerce' ) );
$sku_found = wc_get_product_id_by_sku( $sku );
$this->error( 'product_invalid_sku', __( 'Invalid or duplicated SKU.', 'woocommerce' ), 400, array( 'resource_id' => $sku_found ) );
}
$this->set_prop( 'sku', $sku );
}

View File

@ -168,6 +168,12 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
if ( ! empty( $items['delete'] ) ) {
foreach ( $items['delete'] as $id ) {
$id = (int) $id;
if ( 0 === $id ) {
continue;
}
$_item = new WP_REST_Request( 'DELETE' );
$_item->set_query_params( array( 'id' => $id, 'force' => true ) );
$_response = $this->delete_item( $_item );
@ -353,16 +359,25 @@ abstract class WC_REST_Controller extends WP_REST_Controller {
'description' => __( 'List of created resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'object',
),
),
'update' => array(
'description' => __( 'List of updated resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'object',
),
),
'delete' => array(
'description' => __( 'List of delete resources.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'integer',
),
),
),
);

View File

@ -93,7 +93,7 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
* @return WP_Error|boolean
*/
public function update_item_permissions_check( $request ) {
$post = get_post( $request['id'] );
$post = get_post( (int) $request['id'] );
if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $post->ID ) ) {
return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
@ -109,7 +109,7 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
* @return bool|WP_Error
*/
public function delete_item_permissions_check( $request ) {
$post = get_post( $request['id'] );
$post = get_post( (int) $request['id'] );
if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
@ -625,16 +625,22 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
'validate_callback' => 'rest_validate_request_arg',
);
$params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['include'] = array(
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['offset'] = array(
'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
@ -664,22 +670,30 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
);
$post_type_obj = get_post_type_object( $this->post_type );
if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) {
$params['parent'] = array(
'description' => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'sanitize_callback' => 'wp_parse_id_list',
'default' => array(),
);
$params['parent_exclude'] = array(
'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'sanitize_callback' => 'wp_parse_id_list',
'default' => array(),
);
}
$params['filter'] = array(
'type' => 'object',
'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ),
);

View File

@ -45,7 +45,9 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'name' => array(
'required' => true,
'type' => 'string',
'description' => __( 'Name for the resource.', 'woocommerce' ),
'required' => true,
),
) ),
),
@ -53,6 +55,12 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
));
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -74,6 +82,7 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
@ -378,15 +387,15 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
$term = wp_insert_term( $name, $taxonomy, $args );
if ( is_wp_error( $term ) ) {
$error_data = array( 'status' => 400 );
// If we're going to inform the client that the term exists, give them the identifier
// they can actually use.
if ( ( $term_id = $term->get_error_data( 'term_exists' ) ) ) {
$existing_term = get_term( $term_id, $taxonomy );
$term->add_data( $existing_term->term_id, 'term_exists' );
// If we're going to inform the client that the term exists,
// give them the identifier they can actually use.
if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
$error_data['resource_id'] = $term_id;
}
return $term;
return new WP_Error( $term->get_error_code(), $term->get_error_message(), $error_data );
}
$term = get_term( $term['term_id'], $taxonomy );
@ -471,13 +480,19 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
}
$parent = get_term( (int) $request['parent'], $taxonomy );
$parent_id = (int) $request['parent'];
if ( ! $parent ) {
return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Parent resource does not exist.', 'woocommerce' ), array( 'status' => 400 ) );
if ( 0 === $parent_id ) {
$prepared_args['parent'] = $parent_id;
} else {
$parent = get_term( $parent_id, $taxonomy );
if ( ! $parent ) {
return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Parent resource does not exist.', 'woocommerce' ), array( 'status' => 400 ) );
}
$prepared_args['parent'] = $parent->term_id;
}
$prepared_args['parent'] = $parent->term_id;
}
// Only update the term if we haz something to update.
@ -681,16 +696,22 @@ abstract class WC_REST_Terms_Controller extends WC_REST_Controller {
$params['context']['default'] = 'view';
$params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific ids.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Ensure result set excludes specific ids.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['include'] = array(
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Limit result set to specific ids.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
if ( ! $taxonomy->hierarchical ) {
$params['offset'] = array(

View File

@ -115,8 +115,6 @@ class WC_Admin_Assets {
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'select2' ), WC_VERSION );
wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array(
'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ),
'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ),
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),

View File

@ -1,17 +1,17 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Duplicate product functionality
*
* @author WooThemes
* @author WooCommerce
* @category Admin
* @package WooCommerce/Admin
* @version 2.1.0
* @version 2.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Admin_Duplicate_Product' ) ) :
/**
@ -79,143 +79,57 @@ class WC_Admin_Duplicate_Product {
* Duplicate a product action.
*/
public function duplicate_product_action() {
if ( empty( $_REQUEST['post'] ) ) {
wp_die( __( 'No product to duplicate has been supplied!', 'woocommerce' ) );
}
// Get the original page
$id = isset( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : '';
$product_id = isset( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : '';
check_admin_referer( 'woocommerce-duplicate-product_' . $id );
check_admin_referer( 'woocommerce-duplicate-product_' . $product_id );
$post = $this->get_product_to_duplicate( $id );
$product = wc_get_product( $product_id );
// Copy the page and insert it
if ( ! empty( $post ) ) {
$new_id = $this->duplicate_product( $post );
// If you have written a plugin which uses non-WP database tables to save
// information about a page you can hook this action to dupe that data.
do_action( 'woocommerce_duplicate_product', $new_id, $post );
// Redirect to the edit screen for the new draft page
wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) );
exit;
} else {
if ( false === $product ) {
/* translators: %s: product id */
wp_die( sprintf( __( 'Product creation failed, could not find original product: %s', 'woocommerce' ), $id ) );
}
}
/**
* Function to create the duplicate of the product.
*
* @param mixed $post
* @param int $parent (default: 0)
* @param string $post_status (default: '')
* @return int
*/
public function duplicate_product( $post, $parent = 0, $post_status = '' ) {
global $wpdb;
$new_post_author = wp_get_current_user();
$new_post_date = current_time( 'mysql' );
$new_post_date_gmt = get_gmt_from_date( $new_post_date );
if ( $parent > 0 ) {
$post_parent = $parent;
$post_status = $post_status ? $post_status: 'publish';
$suffix = '';
$post_title = $post->post_title;
} else {
$post_parent = $post->post_parent;
$post_status = $post_status ? $post_status: 'draft';
$suffix = ' ' . __( '(Copy)', 'woocommerce' );
$post_title = $post->post_title . $suffix;
wp_die( sprintf( __( 'Product creation failed, could not find original product: %s', 'woocommerce' ), $product_id ) );
}
// Insert the new template in the post table
$wpdb->insert(
$wpdb->posts,
array(
'post_author' => $new_post_author->ID,
'post_date' => $new_post_date,
'post_date_gmt' => $new_post_date_gmt,
'post_content' => $post->post_content,
'post_content_filtered' => $post->post_content_filtered,
'post_title' => $post_title,
'post_excerpt' => $post->post_excerpt,
'post_status' => $post_status,
'post_type' => $post->post_type,
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
'post_password' => $post->post_password,
'to_ping' => $post->to_ping,
'pinged' => $post->pinged,
'post_modified' => $new_post_date,
'post_modified_gmt' => $new_post_date_gmt,
'post_parent' => $post_parent,
'menu_order' => $post->menu_order,
'post_mime_type' => $post->post_mime_type,
)
);
$duplicate = clone $product;
$duplicate->set_id( 0 );
$duplicate->save();
$new_post_id = $wpdb->insert_id;
// Set title for variations
if ( 'product_variation' === $post->post_type ) {
/* translators: 1: variation id 2: product name */
$post_title = sprintf( __( 'Variation #%1$s of %2$s', 'woocommerce' ), absint( $new_post_id ), esc_html( get_the_title( $post_parent ) ) );
$wpdb->update(
$wpdb->posts,
array(
'post_title' => $post_title,
),
array(
'ID' => $new_post_id,
)
);
$sku = $duplicate->get_sku();
if ( '' !== $duplicate->get_sku() ) {
wc_product_force_unique_sku( $duplicate->get_id() );
}
// Set name and GUID
if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
$wpdb->update(
$wpdb->posts,
array(
'post_name' => wp_unique_post_slug( sanitize_title( $post_title, $new_post_id ), $new_post_id, $post_status, $post->post_type, $post_parent ),
'guid' => get_permalink( $new_post_id ),
),
array(
'ID' => $new_post_id,
)
);
}
// Copy the taxonomies
$this->duplicate_post_taxonomies( $post->ID, $new_post_id, $post->post_type );
// Copy the meta information
$this->duplicate_post_meta( $post->ID, $new_post_id );
// Copy the children (variations)
$exclude = apply_filters( 'woocommerce_duplicate_product_exclude_children', false );
if ( ! $exclude && ( $children_products = get_children( 'post_parent=' . $post->ID . '&post_type=product_variation' ) ) ) {
foreach ( $children_products as $child ) {
$this->duplicate_product( $this->get_product_to_duplicate( $child->ID ), $new_post_id, $child->post_status );
if ( $product->is_type( 'variable' ) || $product->is_type( 'grouped' ) ) {
foreach( $product->get_children() as $child_id ) {
$child = wc_get_product( $child_id );
$child_duplicate = clone $child;
$child_duplicate->set_parent_id( $duplicate->get_id() );
$child_duplicate->set_id( 0 );
$child_duplicate->save();
if ( '' !== $child_duplicate->get_sku() ) {
wc_product_force_unique_sku( $child_duplicate->get_id() );
}
}
}
// Clear cache
clean_post_cache( $new_post_id );
// Hook rename to match other woocommerce_product_* hooks, and to move away from depending on a response from the wp_posts table.
// New hook returns new id and old id.
do_action( 'woocommerce_product_duplicate', $duplicate, $product );
wc_do_deprecated_action( 'woocommerce_duplicate_product', array( $duplicate->get_id(), $this->get_product_to_duplicate( $product_id ) ), '2.7', 'Use woocommerce_product_duplicate action instead.' );
return $new_post_id;
// Redirect to the edit screen for the new draft page
wp_redirect( admin_url( 'post.php?action=edit&post=' . $duplicate->get_id() ) );
exit;
}
/**
* Get a product from the database to duplicate.
*
* @deprecated 2.7.0
* @param mixed $id
* @return WP_Post|bool
* @see duplicate_product
@ -238,58 +152,6 @@ class WC_Admin_Duplicate_Product {
return $post[0];
}
/**
* Copy the taxonomies of a post to another post.
*
* @param mixed $id
* @param mixed $new_id
* @param mixed $post_type
*/
private function duplicate_post_taxonomies( $id, $new_id, $post_type ) {
$exclude = array_filter( apply_filters( 'woocommerce_duplicate_product_exclude_taxonomies', array() ) );
$taxonomies = array_diff( get_object_taxonomies( $post_type ), $exclude );
foreach ( $taxonomies as $taxonomy ) {
$post_terms = wc_get_object_terms( $id, $taxonomy );
$post_terms_count = sizeof( $post_terms );
for ( $i = 0; $i < $post_terms_count; $i++ ) {
wp_set_object_terms( $new_id, (int) $post_terms[ $i ]->term_id, $taxonomy, true );
}
}
}
/**
* Copy the meta information of a post to another post.
*
* @param mixed $id
* @param mixed $new_id
*/
private function duplicate_post_meta( $id, $new_id ) {
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', '_sku' ) ) ) );
if ( sizeof( $exclude ) ) {
$sql .= " AND meta_key NOT IN ( '" . implode( "','", $exclude ) . "' )";
}
$post_meta = $wpdb->get_results( $sql );
if ( sizeof( $post_meta ) ) {
$sql_query_sel = array();
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
foreach ( $post_meta as $post_meta_row ) {
$sql_query_sel[] = $wpdb->prepare( "SELECT %d, %s, %s", $new_id, $post_meta_row->meta_key, $post_meta_row->meta_value );
}
$sql_query .= implode( " UNION ALL ", $sql_query_sel );
$wpdb->query( $sql_query );
}
}
}
endif;

View File

@ -93,8 +93,6 @@ class WC_Admin_Setup_Wizard {
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'select2' ), WC_VERSION );
wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array(
'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ),
'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ),
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),

View File

@ -228,7 +228,7 @@ class WC_Meta_Box_Coupon_Data {
'id' => 'usage_limit_per_user',
'label' => __( 'Usage limit per user', 'woocommerce' ),
'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ),
'description' => __( 'How many times this coupon can be used by an invidual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ),
'description' => __( 'How many times this coupon can be used by an individual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ),
'desc_tip' => true,
'class' => 'short',
'type' => 'number',

View File

@ -111,17 +111,20 @@ class WC_Meta_Box_Order_Actions {
if ( strstr( $action, 'send_email_' ) ) {
// Switch back to the site locale.
if ( function_exists( 'switch_to_locale' ) ) {
switch_to_locale( get_locale() );
}
do_action( 'woocommerce_before_resend_order_emails', $order );
// Ensure gateways are loaded in case they need to insert data into the emails
// Ensure gateways are loaded in case they need to insert data into the emails.
WC()->payment_gateways();
WC()->shipping();
// Load mailer
// Load mailer.
$mailer = WC()->mailer();
$email_to_send = str_replace( 'send_email_', '', $action );
$mails = $mailer->get_emails();
if ( ! empty( $mails ) ) {
@ -136,7 +139,12 @@ class WC_Meta_Box_Order_Actions {
do_action( 'woocommerce_after_resend_order_email', $order, $email_to_send );
// Change the post saved message
// Restore user locale.
if ( function_exists( 'restore_current_locale' ) ) {
restore_current_locale();
}
// Change the post saved message.
add_filter( 'redirect_post_location', array( __CLASS__, 'set_email_sent_message' ) );
} elseif ( 'regenerate_download_permissions' === $action ) {

View File

@ -263,7 +263,7 @@ class WC_Meta_Box_Order_Data {
}
?>
<select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?><option>
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?></option>
</select>
</p>
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>

View File

@ -301,6 +301,11 @@ class WC_Meta_Box_Product_Data {
WC_Admin_Meta_Boxes::add_error( $errors->get_error_message() );
}
/**
* @since 2.7.0 to set props before save.
*/
do_action( 'woocommerce_admin_process_product_object', $product );
$product->save();
if ( $product->is_type( 'variable' ) ) {

View File

@ -81,9 +81,9 @@ class WC_Settings_Tax extends WC_Settings_Page {
public function output() {
global $current_section;
$tax_classes = WC_Tax::get_tax_classes();
$tax_classes = WC_Tax::get_tax_class_slugs();
if ( 'standard' === $current_section || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
if ( 'standard' === $current_section || in_array( $current_section, $tax_classes ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();

View File

@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
</tr>
<tr valign="top" class="">
<th scope="row" class="titledesc">
<label for="zone_locations"><?php esc_html_e( 'Zone region(s)', 'woocommerce' ); ?></label>
<label for="zone_locations"><?php esc_html_e( 'Zone regions', 'woocommerce' ); ?></label>
<?php echo wc_help_tip( __( 'These are regions inside this zone. Customers will be matched against these regions.', 'woocommerce' ) ); ?>
</th>
<td class="forminp">
@ -56,27 +56,26 @@ if ( ! defined( 'ABSPATH' ) ) {
<span class="description"><?php _e( 'Postcodes containing wildcards (e.g. CB23*) and fully numeric ranges (e.g. <code>90210...99000</code>) are also supported.', 'woocommerce' ) ?></span>
</div>
</td>
</tr>
<?php endif; ?>
<?php endif; ?>
</tr>
<tr valign="top" class="">
<th scope="row" class="titledesc">
<label><?php esc_html_e( 'Shipping method(s)', 'woocommerce' ); ?></label>
<label><?php esc_html_e( 'Shipping methods', 'woocommerce' ); ?></label>
<?php echo wc_help_tip( __( 'The following shipping methods apply to customers with shipping addresses within this zone.', 'woocommerce' ) ); ?>
</th>
<td class="">
<table class="wc-shipping-zone-methods widefat">
<thead>
<tr>
<th class="wc-shipping-zone-method-sort"><?php echo wc_help_tip( __( 'Drag and drop to re-order your shipping methods. This is the order in which they will display during checkout.', 'woocommerce' ) ); ?></th>
<th class="wc-shipping-zone-method-title"><?php esc_html_e( 'Title', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-type"><?php esc_html_e( 'Type', 'woocommerce' ); ?></th>
<th class="wc-shipping-zone-method-sort"></th>
<th class="wc-shipping-zone-method-title"><?php esc_html_e( 'Shipping method 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>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5">
<td colspan="4">
<input type="submit" class="button wc-shipping-zone-add-method" value="<?php esc_attr_e( 'Add shipping method', 'woocommerce' ); ?>" />
</td>
</tr>
@ -88,15 +87,13 @@ if ( ! defined( 'ABSPATH' ) ) {
</tbody>
</table>
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary button-hero wc-shipping-zone-method-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled />
<input type="submit" name="submit" id="submit" class="button button-primary button-large wc-shipping-zone-method-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled />
</p>
<script type="text/html" id="tmpl-wc-shipping-zone-method-row-blank">
<tr>
<td class="wc-shipping-zone-method-blank-state" colspan="5">
<p class="main"><?php _e( 'Add shipping methods to this zone', 'woocommerce' ); ?></p>
<td class="wc-shipping-zone-method-blank-state" colspan="4">
<p><?php _e( 'You can add multiple shipping methods within this zone. Only customers within the zone will see them.', 'woocommerce' ); ?></p>
<p><?php _e( 'Click "Add shipping method" to get started.', 'woocommerce' ); ?></p>
</td>
</tr>
</script>
@ -110,9 +107,11 @@ if ( ! defined( 'ABSPATH' ) ) {
<a class="wc-shipping-zone-method-settings" href="admin.php?page=wc-settings&amp;tab=shipping&amp;instance_id={{ data.instance_id }}"><?php _e( 'Edit', 'woocommerce' ); ?></a> | <a href="#" class="wc-shipping-zone-method-delete"><?php _e( 'Delete', 'woocommerce' ); ?></a>
</div>
</td>
<td class="wc-shipping-zone-method-type">{{ data.method_title }}</td>
<td width="1%" class="wc-shipping-zone-method-enabled"><a href="#">{{{ data.enabled_icon }}}</a></td>
<td class="wc-shipping-zone-method-description">{{{ data.method_description }}}</td>
<td class="wc-shipping-zone-method-description">
<strong class="wc-shipping-zone-method-type">{{ data.method_title }}</strong>
{{{ data.method_description }}}
</td>
</tr>
</script>

View File

@ -67,7 +67,9 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'code' => array(
'required' => true,
'description' => __( 'Coupon code.', 'woocommerce' ),
'required' => true,
'type' => 'string',
),
) ),
),
@ -75,6 +77,12 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -96,6 +104,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
),
@ -364,7 +373,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
$coupon->save();
return $coupon->get_id();
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -441,11 +450,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'product_ids' => array(
'description' => __( "List of product ID's the coupon can be used on.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'exclude_product_ids' => array(
'description' => __( "List of product ID's the coupon cannot be used on.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'usage_limit' => array(
@ -472,11 +487,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'product_categories' => array(
'description' => __( "List of category ID's the coupon applies to.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'excluded_product_categories' => array(
'description' => __( "List of category ID's the coupon does not apply to.", 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'exclude_sale_items' => array(
@ -498,11 +519,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Posts_Controller {
'email_restrictions' => array(
'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'string',
),
'context' => array( 'view', 'edit' ),
),
'used_by' => array(
'description' => __( 'List of user IDs who have used the coupon.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),

View File

@ -41,6 +41,12 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'customer_id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),

View File

@ -54,12 +54,18 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'email' => array(
'required' => true,
'type' => 'string',
'description' => __( 'New user email address.', 'woocommerce' ),
),
'username' => array(
'required' => 'no' === get_option( 'woocommerce_registration_generate_username', 'yes' ),
'description' => __( 'New user username.', 'woocommerce' ),
'type' => 'string',
),
'password' => array(
'required' => 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ),
'description' => __( 'New user password.', 'woocommerce' ),
'type' => 'string',
),
) ),
),
@ -67,6 +73,12 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -88,9 +100,14 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
'reassign' => array(),
'reassign' => array(
'default' => 0,
'type' => 'integer',
'description' => __( 'ID to reassign posts to.', 'woocommerce' ),
),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
@ -848,16 +865,22 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
$params['context']['default'] = 'view';
$params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['include'] = array(
'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['offset'] = array(
'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),

View File

@ -14,34 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
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;
}
}
/**
* WC_REST_Exception class.
*/
class WC_REST_Exception extends WC_Data_Exception {}

View File

@ -48,6 +48,12 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -60,7 +66,9 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'note' => array(
'required' => true,
'type' => 'string',
'description' => __( 'Order note content.', 'woocommerce' ),
'required' => true,
),
) ),
),
@ -68,6 +76,16 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -83,6 +101,7 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),

View File

@ -64,6 +64,12 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -80,6 +86,16 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'order_id' => array(
'description' => __( 'The order ID.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -94,10 +110,10 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'args' => array(
'force' => array(
'default' => false,
'default' => true,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),

View File

@ -77,6 +77,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -98,9 +104,9 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
@ -437,7 +443,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
return $order->get_id();
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -466,7 +472,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
return $order->get_id();
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}

View File

@ -48,6 +48,12 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -36,6 +36,95 @@ class WC_REST_Product_Attribute_Terms_Controller extends WC_REST_Terms_Controlle
*/
protected $rest_base = 'products/attributes/(?P<attribute_id>[\d]+)/terms';
/**
* Register the routes for terms.
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'attribute_id' => array(
'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'create_item' ),
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'name' => array(
'type' => 'string',
'description' => __( 'Name for the resource.', 'woocommerce' ),
'required' => true,
),
) ),
),
'schema' => array( $this, 'get_public_item_schema' ),
));
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
'attribute_id' => array(
'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_item' ),
'permission_callback' => array( $this, 'update_item_permissions_check' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_item' ),
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
'args' => array(
'attribute_id' => array(
'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
'type' => 'integer',
),
),
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' ),
) );
}
/**
* Prepare a single product attribute term output for response.
*

View File

@ -60,7 +60,9 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'name' => array(
'required' => true,
'description' => __( 'Name for the resource.', 'woocommerce' ),
'type' => 'string',
'required' => true,
),
) ),
),
@ -68,6 +70,12 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
));
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -88,7 +96,8 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'args' => array(
'force' => array(
'default' => false,
'default' => true,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
@ -300,7 +309,7 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
public function get_item( $request ) {
global $wpdb;
$attribute = $this->get_attribute( $request['id'] );
$attribute = $this->get_attribute( (int) $request['id'] );
if ( is_wp_error( $attribute ) ) {
return $attribute;
@ -408,7 +417,7 @@ class WC_REST_Product_Attributes_Controller extends WC_REST_Controller {
return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
}
$attribute = $this->get_attribute( $request['id'] );
$attribute = $this->get_attribute( (int) $request['id'] );
if ( is_wp_error( $attribute ) ) {
return $attribute;

View File

@ -41,6 +41,16 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the variation.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -53,13 +63,19 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'review' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Review content.', 'woocommerce' ),
),
'name' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Name of the reviewer.', 'woocommerce' ),
),
'email' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Email of the reviewer.', 'woocommerce' ),
),
) ),
),
@ -67,6 +83,16 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -88,6 +114,7 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
),
@ -96,6 +123,12 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
@ -352,8 +385,8 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller {
* @return WP_Error|boolean
*/
public function delete_item( $request ) {
$product_review_id = is_array( $request['id'] ) ? $request['id']['id'] : $request['id'];
$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
$product_review_id = absint( is_array( $request['id'] ) ? $request['id']['id'] : $request['id'] );
$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
$product_review = get_comment( $product_review_id );
if ( empty( $product_review_id ) || empty( $product_review->comment_ID ) || empty( $product_review->comment_post_ID ) ) {

View File

@ -56,6 +56,12 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -71,6 +77,16 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the variation.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -92,14 +108,20 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
'args' => array(
'product_id' => array(
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
@ -264,7 +286,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
* @return WP_Error|boolean
*/
public function delete_item( $request ) {
$request['id'] = is_array( $request['id'] ) ? $request['id']['id'] : $request['id'];
$request['id'] = absint( is_array( $request['id'] ) ? $request['id']['id'] : $request['id'] );
return parent::delete_item( $request );
}

View File

@ -72,6 +72,12 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -94,8 +100,8 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'force' => array(
'default' => false,
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
'type' => 'boolean',
),
'reassign' => array(),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
@ -766,7 +772,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
return $response;
} catch ( WC_Data_Exception $e ) {
$this->delete_post( $product_id );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
$this->delete_post( $product_id );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
@ -805,7 +811,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
return rest_ensure_response( $response );
} catch ( WC_Data_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -852,10 +858,10 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
}
if ( ! wp_attachment_is_image( $attachment_id ) ) {
throw new WC_REST_Exception( 'woocommerce_product_ĩnvalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
throw new WC_REST_Exception( 'woocommerce_product_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
}
if ( isset( $image['position'] ) && 0 === $image['position'] ) {
if ( isset( $image['position'] ) && 0 === absint( $image['position'] ) ) {
$product->set_image_id( $attachment_id );
} else {
$gallery[] = $attachment_id;
@ -1050,8 +1056,6 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
* @return WC_Product
*/
protected function set_product_meta( $product, $request ) {
global $wpdb;
// Virtual.
if ( isset( $request['virtual'] ) ) {
$product->set_virtual( $request['virtual'] );
@ -1216,7 +1220,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
$product->set_manage_stock( 'no' );
$product->set_backorders( 'no' );
$product->set_stock_quantity( '' );
$product->set_stock_status( $status );
$product->set_stock_status( $stock_status );
} elseif ( $product->is_type( 'external' ) ) {
$product->set_manage_stock( 'no' );
$product->set_backorders( 'no' );
@ -1589,7 +1593,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
*/
protected function delete_post( $id ) {
if ( ! empty( $id->ID ) ) {
$id = $post->ID;
$id = $id->ID;
} elseif ( ! is_numeric( $id ) || 0 >= $id ) {
return;
}
@ -2043,17 +2047,26 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'related_ids' => array(
'description' => __( 'List of related products IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'upsell_ids' => array(
'description' => __( 'List of up-sell products IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'cross_sell_ids' => array(
'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
),
'parent_id' => array(
@ -2533,6 +2546,9 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
'grouped_products' => array(
'description' => __( 'List of grouped products ID.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
@ -2622,7 +2638,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
$params['tax_class'] = array(
'description' => __( 'Limit result set to products with a specific tax class.', 'woocommerce' ),
'type' => 'string',
'enum' => array_map( 'sanitize_title', array_merge( array( 'standard' ), WC_Tax::get_tax_classes() ) ),
'enum' => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ),
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);

View File

@ -351,6 +351,9 @@ class WC_REST_Report_Sales_Controller extends WC_REST_Controller {
'totals' => array(
'description' => __( 'Totals.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'array',
),
'context' => array( 'view' ),
'readonly' => true,
),

View File

@ -34,6 +34,12 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<group>[\w-]+)', array(
'args' => array(
'group' => array(
'description' => __( 'Settings group ID.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -43,6 +49,12 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<group>[\w-]+)/batch', array(
'args' => array(
'group' => array(
'description' => __( 'Settings group ID.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'batch_items' ),
@ -53,6 +65,16 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<group>[\w-]+)/(?P<id>[\w-]+)', array(
'args' => array(
'group' => array(
'description' => __( 'Settings group ID.', 'woocommerce' ),
'type' => 'string',
),
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -497,10 +519,10 @@ class WC_REST_Settings_Options_Controller extends WC_REST_Controller {
'readonly' => true,
),
'options' => array(
'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
'type' => 'object',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
);

View File

@ -48,6 +48,12 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),

View File

@ -27,6 +27,12 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d-]+)/locations', array(
'args' => array(
'id' => array(
'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -49,7 +55,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
* @return WP_REST_Response|WP_Error
*/
public function get_items( $request ) {
$zone = $this->get_zone( $request['id'] );
$zone = $this->get_zone( (int) $request['id'] );
if ( is_wp_error( $zone ) ) {
return $zone;
@ -74,7 +80,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
* @return WP_REST_Response|WP_Error
*/
public function update_items( $request ) {
$zone = $this->get_zone( $request['id'] );
$zone = $this->get_zone( (int) $request['id'] );
if ( is_wp_error( $zone ) ) {
return $zone;
@ -111,7 +117,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
// Wrap the data in a response object.
$response = rest_ensure_response( $data );
$response->add_links( $this->prepare_links( $request['id'] ) );
$response->add_links( $this->prepare_links( (int) $request['id'] ) );
return $response;
}

View File

@ -27,6 +27,12 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d-]+)/methods', array(
'args' => array(
'zone_id' => array(
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -42,6 +48,16 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d-]+)/methods/(?P<instance_id>[\d-]+)', array(
'args' => array(
'zone_id' => array(
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
'type' => 'integer',
),
'instance_id' => array(
'description' => __( 'Unique ID for the instance.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -60,6 +76,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
),

View File

@ -42,6 +42,12 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -60,6 +66,7 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
),
),

View File

@ -282,6 +282,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Database tables', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
),
),
@ -289,6 +292,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Active plugins', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
'theme' => array(
'description' => __( 'Theme', 'woocommerce' ),
@ -340,6 +346,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Template overrides', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
'parent_name' => array(
'description' => __( 'Parent theme name', 'woocommerce' ),
@ -413,6 +422,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'Taxonomy terms for product/order statuses', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
),
),
@ -437,6 +449,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
'description' => __( 'WooCommerce pages', 'woocommerce' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
'items' => array(
'type' => 'string',
),
),
),
);

View File

@ -38,17 +38,23 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
* Register the routes for /system_status/tools/*.
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -64,15 +70,15 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
) );
}
/**
/**
* Check whether a given request has permission to view system status tools.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|boolean
*/
public function get_items_permissions_check( $request ) {
if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) {
return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
@ -122,10 +128,10 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ),
),
'delete_orphaned_variations' => array(
'name' => __( 'Orphaned variations', 'woocommerce' ),
'button' => __( 'Delete orphaned variations', 'woocommerce' ),
'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ),
),
'name' => __( 'Orphaned variations', 'woocommerce' ),
'button' => __( 'Delete orphaned variations', 'woocommerce' ),
'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ),
),
'recount_terms' => array(
'name' => __( 'Term counts', 'woocommerce' ),
'button' => __( 'Recount terms', 'woocommerce' ),
@ -173,7 +179,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
return apply_filters( 'woocommerce_debug_tools', $tools );
}
/**
/**
* Get a list of system status tools.
*
* @param WP_REST_Request $request Full details about the request.
@ -260,7 +266,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
return $response;
}
/**
/**
* Get the system status tools schema, conforming to JSON Schema.
*
* @return array
@ -393,8 +399,8 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
break;
case 'delete_orphaned_variations' :
/**
* Delete orphans
*/
* Delete orphans
*/
$result = absint( $wpdb->query( "DELETE products
FROM {$wpdb->posts} products
LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent

View File

@ -57,6 +57,12 @@ class WC_REST_Tax_Classes_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<slug>\w[\w\s\-]*)', array(
'args' => array(
'slug' => array(
'description' => __( 'Unique slug for the resource.', 'woocommerce' ),
'type' => 'string',
),
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_item' ),
@ -64,6 +70,7 @@ class WC_REST_Tax_Classes_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),

View File

@ -57,6 +57,12 @@ class WC_REST_Taxes_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -78,6 +84,7 @@ class WC_REST_Taxes_Controller extends WC_REST_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
@ -626,7 +633,7 @@ class WC_REST_Taxes_Controller extends WC_REST_Controller {
'description' => __( 'Tax class.', 'woocommerce' ),
'type' => 'string',
'default' => 'standard',
'enum' => array_merge( array( 'standard' ), array_map( 'sanitize_title', WC_Tax::get_tax_classes() ) ),
'enum' => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ),
'context' => array( 'view', 'edit' ),
),
),
@ -646,16 +653,22 @@ class WC_REST_Taxes_Controller extends WC_REST_Controller {
$params['context']['default'] = 'view';
$params['exclude'] = array(
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['include'] = array(
'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ),
'type' => 'array',
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'default' => array(),
'sanitize_callback' => 'wp_parse_id_list',
);
$params['offset'] = array(
'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
@ -684,7 +697,7 @@ class WC_REST_Taxes_Controller extends WC_REST_Controller {
);
$params['class'] = array(
'description' => __( 'Sort by tax class.', 'woocommerce' ),
'enum' => array_merge( array( 'standard' ), array_map( 'sanitize_title', WC_Tax::get_tax_classes() ) ),
'enum' => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ),
'sanitize_callback' => 'sanitize_title',
'type' => 'string',
'validate_callback' => 'rest_validate_request_arg',

View File

@ -41,6 +41,12 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Controller {
*/
public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
'args' => array(
'webhook_id' => array(
'description' => __( 'Unique identifier for the webhook.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
@ -51,6 +57,16 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'webhook_id' => array(
'description' => __( 'Unique identifier for the webhook.', 'woocommerce' ),
'type' => 'integer',
),
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -251,6 +267,9 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Controller {
'type' => 'array',
'context' => array( 'view' ),
'readonly' => true,
'items' => array(
'type' => 'string',
),
),
'request_body' => array(
'description' => __( 'Request body.', 'woocommerce' ),
@ -275,6 +294,9 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Controller {
'type' => 'array',
'context' => array( 'view' ),
'readonly' => true,
'items' => array(
'type' => 'string',
),
),
'response_body' => array(
'description' => __( 'The response body from the receiving server.', 'woocommerce' ),

View File

@ -67,13 +67,19 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
'topic' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Webhook topic.', 'woocommerce' ),
),
'delivery_url' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Webhook delivery URL.', 'woocommerce' ),
),
'secret' => array(
'required' => true,
'required' => true,
'type' => 'string',
'description' => __( 'Webhook secret.', 'woocommerce' ),
),
) ),
),
@ -81,6 +87,12 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
) );
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
@ -102,6 +114,7 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'args' => array(
'force' => array(
'default' => false,
'type' => 'boolean',
'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
),
),
@ -514,6 +527,9 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'readonly' => true,
'items' => array(
'type' => 'string',
),
),
'delivery_url' => array(
'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ),

View File

@ -76,7 +76,7 @@ class WC_AJAX {
if ( $action = $wp_query->get( 'wc-ajax' ) ) {
self::wc_ajax_headers();
do_action( 'wc_ajax_' . sanitize_text_field( $action ) );
die();
wp_die();
}
}
@ -191,7 +191,7 @@ class WC_AJAX {
}
wc_print_notices();
die();
wp_die();
}
/**
@ -210,7 +210,7 @@ class WC_AJAX {
}
wc_print_notices();
die();
wp_die();
}
/**
@ -241,7 +241,7 @@ class WC_AJAX {
wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
WC()->cart->calculate_totals();
woocommerce_cart_totals();
die();
wp_die();
}
/**
@ -388,7 +388,7 @@ class WC_AJAX {
public static function checkout() {
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
WC()->checkout()->process_checkout();
die( 0 );
wp_die( 0 );
}
/**
@ -398,7 +398,7 @@ class WC_AJAX {
ob_start();
if ( empty( $_POST['product_id'] ) || ! ( $variable_product = wc_get_product( absint( $_POST['product_id'] ) ) ) ) {
die();
wp_die();
}
$data_store = WC_Data_Store::load( 'product' );
@ -429,7 +429,7 @@ class WC_AJAX {
}
wp_safe_redirect( wp_get_referer() ? remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() ) : admin_url( 'edit.php?post_type=product' ) );
die();
wp_die();
}
/**
@ -447,7 +447,7 @@ class WC_AJAX {
}
wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=shop_order' ) );
die();
wp_die();
}
/**
@ -459,7 +459,7 @@ class WC_AJAX {
check_ajax_referer( 'add-attribute', 'security' );
if ( ! current_user_can( 'edit_products' ) ) {
die( -1 );
wp_die( -1 );
}
$i = absint( $_POST['i'] );
@ -477,7 +477,7 @@ class WC_AJAX {
}
include( 'admin/meta-boxes/views/html-product-attribute.php' );
die();
wp_die();
}
/**
@ -508,7 +508,7 @@ class WC_AJAX {
}
}
}
die( -1 );
wp_die( -1 );
}
/**
@ -528,7 +528,7 @@ class WC_AJAX {
}
}
die( -1 );
wp_die( -1 );
}
/**
@ -538,7 +538,7 @@ class WC_AJAX {
check_ajax_referer( 'save-attributes', 'security' );
if ( ! current_user_can( 'edit_products' ) ) {
die( -1 );
wp_die( -1 );
}
parse_str( $_POST['data'], $data );
@ -551,7 +551,7 @@ class WC_AJAX {
$product->set_attributes( $attributes );
$product->save();
die();
wp_die();
}
/**
@ -562,7 +562,7 @@ class WC_AJAX {
check_ajax_referer( 'add-variation', 'security' );
if ( ! current_user_can( 'edit_products' ) ) {
die( -1 );
wp_die( -1 );
}
global $post; // Set $post global so its available, like within the admin screens
@ -577,7 +577,7 @@ class WC_AJAX {
$variation = get_post( $variation_id );
$variation_data = array_merge( array_map( 'maybe_unserialize', get_post_custom( $variation_id ) ), wc_get_product_variation_attributes( $variation_id ) ); // kept for BW compat.
include( 'admin/meta-boxes/views/html-variation-admin.php' );
die();
wp_die();
}
/**
@ -587,7 +587,7 @@ class WC_AJAX {
check_ajax_referer( 'link-variations', 'security' );
if ( ! current_user_can( 'edit_products' ) ) {
die( -1 );
wp_die( -1 );
}
wc_maybe_define_constant( 'WC_MAX_LINKED_VARIATIONS', 49 );
@ -596,7 +596,7 @@ class WC_AJAX {
$post_id = intval( $_POST['post_id'] );
if ( ! $post_id ) {
die();
wp_die();
}
$variations = array();
@ -635,7 +635,7 @@ class WC_AJAX {
$data_store = $product->get_data_store();
$data_store->sort_all_product_variations( $product->get_id() );
die();
wp_die();
}
/**
@ -645,7 +645,7 @@ class WC_AJAX {
check_ajax_referer( 'revoke-access', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$download_id = $_POST['download_id'];
$product_id = intval( $_POST['product_id'] );
@ -656,7 +656,7 @@ class WC_AJAX {
do_action( 'woocommerce_ajax_revoke_access_to_product_download', $download_id, $product_id, $order_id, $permission_id );
die();
wp_die();
}
/**
@ -667,7 +667,7 @@ class WC_AJAX {
check_ajax_referer( 'grant-access', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
global $wpdb;
@ -689,7 +689,7 @@ class WC_AJAX {
$files = $product->get_downloads();
if ( ! $order->get_billing_email() ) {
die();
wp_die();
}
if ( ! empty( $files ) ) {
@ -709,7 +709,7 @@ class WC_AJAX {
}
}
}
die();
wp_die();
}
/**
@ -719,7 +719,7 @@ class WC_AJAX {
check_ajax_referer( 'get-customer-details', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$user_id = absint( $_POST['user_id'] );
@ -740,7 +740,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
try {
@ -776,7 +776,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
try {
@ -805,7 +805,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
try {
@ -838,7 +838,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
try {
@ -871,7 +871,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$order_item_ids = $_POST['order_item_ids'];
@ -885,7 +885,7 @@ class WC_AJAX {
wc_delete_order_item( absint( $id ) );
}
}
die();
wp_die();
}
/**
@ -895,7 +895,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$order_id = absint( $_POST['order_id'] );
@ -906,7 +906,7 @@ class WC_AJAX {
// Return HTML items
$order = wc_get_order( $order_id );
include( 'admin/meta-boxes/views/html-order-items.php' );
die();
wp_die();
}
/**
@ -915,7 +915,7 @@ class WC_AJAX {
public static function reduce_order_item_stock() {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$order_id = absint( $_POST['order_id'] );
$order_item_ids = isset( $_POST['order_item_ids'] ) ? $_POST['order_item_ids'] : array();
@ -945,7 +945,7 @@ class WC_AJAX {
}
echo implode( ', ', $return );
}
die();
wp_die();
}
/**
@ -954,7 +954,7 @@ class WC_AJAX {
public static function increase_order_item_stock() {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$order_id = absint( $_POST['order_id'] );
$order_item_ids = isset( $_POST['order_item_ids'] ) ? $_POST['order_item_ids'] : array();
@ -985,7 +985,7 @@ class WC_AJAX {
}
echo implode( ', ', $return );
}
die();
wp_die();
}
/**
@ -995,7 +995,7 @@ class WC_AJAX {
check_ajax_referer( 'calc-totals', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$order_id = absint( $_POST['order_id'] );
@ -1020,7 +1020,7 @@ class WC_AJAX {
// Return HTML items
$order = wc_get_order( $order_id );
include( 'admin/meta-boxes/views/html-order-items.php' );
die();
wp_die();
}
/**
@ -1030,7 +1030,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
if ( isset( $_POST['order_id'], $_POST['items'] ) ) {
@ -1047,7 +1047,7 @@ class WC_AJAX {
$order = wc_get_order( $order_id );
include( 'admin/meta-boxes/views/html-order-items.php' );
}
die();
wp_die();
}
/**
@ -1057,14 +1057,14 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
// Return HTML items
$order_id = absint( $_POST['order_id'] );
$order = wc_get_order( $order_id );
include( 'admin/meta-boxes/views/html-order-items.php' );
die();
wp_die();
}
/**
@ -1074,7 +1074,7 @@ class WC_AJAX {
check_ajax_referer( 'add-order-note', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$post_id = absint( $_POST['post_id'] );
@ -1096,7 +1096,7 @@ class WC_AJAX {
echo '</div><p class="meta"><a href="#" class="delete_note">' . __( 'Delete note', 'woocommerce' ) . '</a></p>';
echo '</li>';
}
die();
wp_die();
}
/**
@ -1106,7 +1106,7 @@ class WC_AJAX {
check_ajax_referer( 'delete-order-note', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$note_id = (int) $_POST['note_id'];
@ -1114,7 +1114,7 @@ class WC_AJAX {
if ( $note_id > 0 ) {
wp_delete_comment( $note_id );
}
die();
wp_die();
}
/**
@ -1129,7 +1129,7 @@ class WC_AJAX {
$term = wc_clean( empty( $term ) ? stripslashes( $_GET['term'] ) : $term );
if ( empty( $term ) ) {
die();
wp_die();
}
$data_store = WC_Data_Store::load( 'product' );
@ -1209,14 +1209,14 @@ class WC_AJAX {
check_ajax_referer( 'search-customers', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$term = wc_clean( stripslashes( $_GET['term'] ) );
$exclude = array();
if ( empty( $term ) ) {
die();
wp_die();
}
$data_store = WC_Data_Store::load( 'customer' );
@ -1248,7 +1248,7 @@ class WC_AJAX {
// check permissions again and make sure we have what we need
if ( ! current_user_can( 'edit_products' ) || empty( $_POST['id'] ) ) {
die( -1 );
wp_die( -1 );
}
$id = (int) $_POST['id'];
@ -1257,7 +1257,7 @@ class WC_AJAX {
$term = get_term_by( 'id', $id, $taxonomy );
if ( ! $id || ! $term || ! $taxonomy ) {
die( 0 );
wp_die( 0 );
}
wc_reorder_terms( $term, $next_id, $taxonomy );
@ -1266,7 +1266,7 @@ class WC_AJAX {
if ( $term && sizeof( $children ) ) {
echo 'children';
die();
wp_die();
}
}
@ -1279,7 +1279,7 @@ class WC_AJAX {
global $wpdb;
if ( ! current_user_can( 'edit_products' ) || empty( $_POST['id'] ) ) {
die( -1 );
wp_die( -1 );
}
$sorting_id = absint( $_POST['id'] );
@ -1325,7 +1325,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$order_id = absint( $_POST['order_id'] );
@ -1449,7 +1449,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
if ( ! current_user_can( 'edit_shop_orders' ) ) {
die( -1 );
wp_die( -1 );
}
$refund_ids = array_map( 'absint', is_array( $_POST['refund_id'] ) ? $_POST['refund_id'] : array( $_POST['refund_id'] ) );
@ -1461,7 +1461,7 @@ class WC_AJAX {
do_action( 'woocommerce_refund_deleted', $refund_id, $order_id );
}
}
die();
wp_die();
}
/**
@ -1469,10 +1469,10 @@ class WC_AJAX {
*/
public static function rated() {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
die( -1 );
wp_die( -1 );
}
update_option( 'woocommerce_admin_footer_text_rated', 1 );
die();
wp_die();
}
/**
@ -1486,7 +1486,7 @@ class WC_AJAX {
check_ajax_referer( 'update-api-key', 'security' );
if ( ! current_user_can( 'manage_woocommerce' ) ) {
die( -1 );
wp_die( -1 );
}
try {
@ -1575,7 +1575,7 @@ class WC_AJAX {
check_ajax_referer( 'load-variations', 'security' );
if ( ! current_user_can( 'edit_products' ) || empty( $_POST['product_id'] ) ) {
die( -1 );
wp_die( -1 );
}
// Set $post global so its available, like within the admin screens
@ -1609,7 +1609,7 @@ class WC_AJAX {
$loop++;
}
}
die();
wp_die();
}
/**
@ -1622,7 +1622,7 @@ class WC_AJAX {
// Check permissions again and make sure we have what we need
if ( ! current_user_can( 'edit_products' ) || empty( $_POST ) || empty( $_POST['product_id'] ) ) {
die( -1 );
wp_die( -1 );
}
$product_id = absint( $_POST['product_id'] );
@ -1644,7 +1644,7 @@ class WC_AJAX {
delete_option( 'woocommerce_meta_box_errors' );
}
die();
wp_die();
}
/**
@ -1982,7 +1982,7 @@ class WC_AJAX {
// Check permissions again and make sure we have what we need
if ( ! current_user_can( 'edit_products' ) || empty( $_POST['product_id'] ) || empty( $_POST['bulk_action'] ) ) {
die( -1 );
wp_die( -1 );
}
$product_id = absint( $_POST['product_id'] );
@ -2009,7 +2009,7 @@ class WC_AJAX {
do_action( 'woocommerce_bulk_edit_variations', $bulk_action, $data, $product_id, $variations );
WC_Product_Variable::sync( $product_id );
wc_delete_product_transients( $product_id );
die();
wp_die();
}
/**

View File

@ -413,6 +413,7 @@ class WC_Checkout {
foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) {
/** @var WC_Shipping_Rate $shipping_rate */
$shipping_rate = $package['rates'][ $chosen_shipping_methods[ $package_key ] ];
$item = new WC_Order_Item_Shipping();
$item->legacy_package_key = $package_key; // @deprecated For legacy actions.
@ -423,9 +424,12 @@ class WC_Checkout {
'taxes' => array(
'total' => $shipping_rate->taxes,
),
'meta_data' => $shipping_rate->get_meta_data(),
) );
foreach ( $shipping_rate->get_meta_data() as $key => $value ) {
$item->add_meta_data( $key, $value, true );
}
/**
* Action hook to adjust item before save.
* @since 2.7.0
@ -957,8 +961,11 @@ class WC_Checkout {
return wc_clean( $_POST[ $input ] );
} else {
if ( has_filter( 'woocommerce_checkout_get_value' ) ) {
return apply_filters( 'woocommerce_checkout_get_value', null, $input );
$value = apply_filters( 'woocommerce_checkout_get_value', null, $input );
if ( $value !== null ) {
return $value;
}
if ( is_callable( array( WC()->customer, "get_$input" ) ) ) {

View File

@ -116,7 +116,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
* @return string
*/
protected function get_hook_prefix() {
return 'woocommerce_get_coupon_';
return 'woocommerce_coupon_get_';
}
/*

View File

@ -119,7 +119,7 @@ class WC_Customer extends WC_Legacy_Customer {
* @return string
*/
protected function get_hook_prefix() {
return 'woocommerce_get_customer_';
return 'woocommerce_customer_get_';
}
/**

View File

@ -4,10 +4,10 @@
*
* Extends Exception to provide additional data.
*
* @author WooThemes
* @category Core
* @package WooCommerce
* @since 2.7
* @author WooThemes
* @category Core
* @package WooCommerce
* @since 2.7
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -15,34 +15,54 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* WC_Data_Exception class
* WC_Data_Exception class.
*/
class WC_Data_Exception extends Exception {
/** @var string sanitized error code */
/**
* Sanitized error code.
*
* @var string
*/
protected $error_code;
/**
* Error extra data.
*
* @var array
*/
protected $error_data;
/**
* Setup exception.
*
* error code - machine-readable, e.g. `woocommerce_invalid_product_id`
* error message - friendly message, e.g. 'Product ID is invalid'
* http status code - proper HTTP status code to respond with, e.g. 400
*
* @param string $error_code
* @param string $error_message user-friendly translated error message
* @param int $http_status_code HTTP status code to respond with
* @param string $code Machine-readable error code, e.g `woocommerce_invalid_product_id`.
* @param string $message User-friendly translated error message, e.g. 'Product ID is invalid'.
* @param int $http_status_code Proper HTTP status code to respond with, e.g. 400.
* @param array $data Extra error data.
*/
public function __construct( $error_code, $error_message, $http_status_code = 400 ) {
$this->error_code = $error_code;
parent::__construct( $error_message, $http_status_code );
public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
$this->error_code = $code;
$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
parent::__construct( $message, $http_status_code );
}
/**
* Returns the error code
* Returns the error code.
*
* @return string
*/
public function getErrorCode() {
return $this->error_code;
}
/**
* Returns error data.
*
* @return array
*/
public function getErrorData() {
return $this->error_data;
}
}

View File

@ -448,6 +448,7 @@ class WC_Frontend_Scripts {
'controlNav' => 'thumbnails',
'slideshow' => false,
'animationSpeed' => 500,
'animationLoop' => false, // Breaks photoswipe pagination if true.
) ),
);
break;
@ -513,8 +514,6 @@ class WC_Frontend_Scripts {
return array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ),
'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ),
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),

View File

@ -43,6 +43,23 @@ class WC_Logger implements WC_Logger_Interface {
$handlers = apply_filters( 'woocommerce_register_log_handlers', array() );
}
$register_handlers = array();
foreach ( $handlers as $handler ) {
$implements = class_implements( $handler );
if ( is_object( $handler ) && is_array( $implements ) && in_array( 'WC_Log_Handler_Interface', $implements ) ) {
$register_handlers[] = $handler;
} else {
wc_doing_it_wrong(
__METHOD__,
sprintf(
__( 'The provided handler <code>%s</code> does not implement WC_Log_Handler_Interface.', 'woocommerce' ),
esc_html( is_object( $handler ) ? get_class( $handler ) : $handler )
),
'2.7'
);
}
}
if ( null !== $threshold ) {
$threshold = WC_Log_Levels::get_level_severity( $threshold );
} elseif ( defined( 'WC_LOG_THRESHOLD' ) && WC_Log_Levels::is_valid_level( WC_LOG_THRESHOLD ) ) {
@ -51,7 +68,7 @@ class WC_Logger implements WC_Logger_Interface {
$threshold = null;
}
$this->handlers = $handlers;
$this->handlers = $register_handlers;
$this->threshold = $threshold;
}
@ -61,7 +78,7 @@ class WC_Logger implements WC_Logger_Interface {
* @param string $level emergency|alert|critical|error|warning|notice|info|debug
* @return bool True if the log should be handled.
*/
public function should_handle( $level ) {
protected function should_handle( $level ) {
if ( null === $this->threshold ) {
return true;
}
@ -102,9 +119,7 @@ class WC_Logger implements WC_Logger_Interface {
*/
public function log( $level, $message, $context = array() ) {
if ( ! WC_Log_Levels::is_valid_level( $level ) ) {
$class = __CLASS__;
$method = __FUNCTION__;
wc_doing_it_wrong( "{$class}::{$method}", sprintf( __( 'WC_Logger::log was called with an invalid level "%s".', 'woocommerce' ), $level ), '2.7' );
wc_doing_it_wrong( __METHOD__, sprintf( __( 'WC_Logger::log was called with an invalid level "%s".', 'woocommerce' ), $level ), '2.7' );
}
if ( $this->should_handle( $level ) ) {

View File

@ -41,7 +41,7 @@ class WC_Order_Item_Fee extends WC_Order_Item {
* @throws WC_Data_Exception
*/
public function set_tax_class( $value ) {
if ( $value && ! in_array( $value, WC_Tax::get_tax_classes() ) ) {
if ( $value && ! in_array( $value, WC_Tax::get_tax_class_slugs() ) ) {
$this->error( 'order_item_fee_invalid_tax_class', __( 'Invalid tax class', 'woocommerce' ) );
}
$this->set_prop( 'tax_class', $value );

View File

@ -57,7 +57,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
* @throws WC_Data_Exception
*/
public function set_tax_class( $value ) {
if ( $value && ! in_array( $value, WC_Tax::get_tax_classes() ) ) {
if ( $value && ! in_array( $value, WC_Tax::get_tax_class_slugs() ) ) {
$this->error( 'order_item_product_invalid_tax_class', __( 'Invalid tax class', 'woocommerce' ) );
}
$this->set_prop( 'tax_class', $value );

View File

@ -57,7 +57,6 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
* @param int|object|array $item ID to load from the DB, or WC_Order_Item Object
*/
public function __construct( $item = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $item );
if ( $item instanceof WC_Order_Item ) {

View File

@ -38,16 +38,6 @@ class WC_Order_Refund extends WC_Abstract_Order {
'refunded_by' => 0,
);
/**
* Extend the abstract _data properties and then read the order object.
*
* @param int|object|WC_Order $read Order to init.
*/
public function __construct( $read = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $read );
}
/**
* Get internal type (post type.)
* @return string

View File

@ -340,6 +340,22 @@ class WC_Order extends WC_Abstract_Order {
);
}
/**
* Expands the shipping and billing information in the changes array.
*/
public function get_changes() {
$changed_props = parent::get_changes();
$subs = array( 'shipping', 'billing' );
foreach ( $subs as $sub ) {
if ( ! empty( $changed_props[ $sub ] ) ) {
foreach ( $changed_props[ $sub ] as $sub_prop => $value ) {
$changed_props[ $sub . '_' . $sub_prop ] = $value;
}
}
}
return $changed_props;
}
/**
* get_order_number function.
*

View File

@ -26,15 +26,6 @@ class WC_Product_External extends WC_Product {
'button_text' => '',
);
/**
* Merges external product data into the parent object.
* @param int|WC_Product|object $product Product to init.
*/
public function __construct( $product = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $product );
}
/**
* Get internal type.
* @return string

View File

@ -25,15 +25,6 @@ class WC_Product_Grouped extends WC_Product {
'children' => array(),
);
/**
* Merges grouped product data into the parent object.
* @param int|WC_Product|object $product Product to init.
*/
public function __construct( $product = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $product );
}
/**
* Get internal type.
* @return string

View File

@ -455,7 +455,7 @@ class WC_Product_Variable extends WC_Product {
$data_store->sync_stock_status( $product );
self::sync_attributes( $product ); // Legacy update of attributes.
do_action( 'woocommerce_variable_product_sync', $product->get_id(), $product->get_visible_children( 'edit' ), $save );
do_action( 'woocommerce_variable_product_sync', $product->get_id(), $product->get_visible_children(), $save );
if ( $save ) {
$product->save();

View File

@ -44,7 +44,7 @@ class WC_Product_Variation extends WC_Product_Simple {
* @return string
*/
protected function get_hook_prefix() {
return 'woocommerce_get_product_variation_';
return 'woocommerce_product_variation_get_';
}
/**
@ -299,6 +299,16 @@ class WC_Product_Variation extends WC_Product_Simple {
$this->parent_data = $parent_data;
}
/**
* Get the parent data array for this variation.
*
* @since 2.7.0
* @return array
*/
public function get_parent_data() {
return $this->parent_data;
}
/**
* Set attributes. Unlike the parent product which uses terms, variations are assigned
* specific attributes using name value pairs.

View File

@ -285,7 +285,9 @@ class WC_Query {
}
// Define a variable so we know this is the front page shop later on
define( 'SHOP_IS_ON_FRONT', true );
if ( ! defined( 'SHOP_IS_ON_FRONT' ) ) {
define( 'SHOP_IS_ON_FRONT', true );
}
// Get the actual WP page to avoid errors and let us use is_front_page()
// This is hacky but works. Awaiting https://core.trac.wordpress.org/ticket/21096

View File

@ -238,7 +238,7 @@ class WC_Shipping {
* @param array $packages multi-dimensional array of cart items to calc shipping for
*/
public function calculate_shipping( $packages = array() ) {
$this->shipping_total = null;
$this->shipping_total = 0;
$this->shipping_taxes = array();
$this->packages = array();
@ -393,7 +393,7 @@ class WC_Shipping {
*/
public function reset_shipping() {
unset( WC()->session->chosen_shipping_methods );
$this->shipping_total = null;
$this->shipping_total = 0;
$this->shipping_taxes = array();
$this->packages = array();
}

View File

@ -410,8 +410,8 @@ class WC_Tax {
LEFT OUTER JOIN {$wpdb->prefix}woocommerce_tax_rate_locations as locations ON tax_rates.tax_rate_id = locations.tax_rate_id
LEFT OUTER JOIN {$wpdb->prefix}woocommerce_tax_rate_locations as locations2 ON tax_rates.tax_rate_id = locations2.tax_rate_id
WHERE 1=1 AND " . implode( ' AND ', $criteria ) . "
GROUP BY tax_rate_id
ORDER BY tax_rate_priority
GROUP BY tax_rates.tax_rate_id
ORDER BY tax_rates.tax_rate_priority
" );
$found_rates = self::sort_rates( $found_rates );
@ -550,10 +550,9 @@ class WC_Tax {
// If multiple classes are found, use the first one found unless a standard rate item is found. This will be the first listed in the 'additonal tax class' section.
if ( sizeof( $cart_tax_classes ) > 1 && ! in_array( '', $cart_tax_classes ) ) {
$tax_classes = self::get_tax_classes();
$tax_classes = self::get_tax_class_slugs();
foreach ( $tax_classes as $tax_class ) {
$tax_class = sanitize_title( $tax_class );
if ( in_array( $tax_class, $cart_tax_classes ) ) {
$matched_tax_rates = self::find_shipping_rates( array(
'country' => $country,
@ -691,12 +690,22 @@ class WC_Tax {
/**
* Get store tax classes.
* @return array
* @return array Array of class names ("Reduced rate", "Zero rate", etc).
*/
public static function get_tax_classes() {
return array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
}
/**
* Get store tax classes as slugs.
*
* @since 2.7.0
* @return array Array of class slugs ("reduced-rate", "zero-rate", etc).
*/
public static function get_tax_class_slugs() {
return array_map( 'sanitize_title', self::get_tax_classes() );
}
/**
* format the city.
* @param string $city
@ -759,9 +768,9 @@ class WC_Tax {
* @return string
*/
public static function format_tax_rate_class( $class ) {
$class = sanitize_title( $class );
$sanitized_classes = array_map( 'sanitize_title', self::get_tax_classes() );
if ( ! in_array( $class, $sanitized_classes ) ) {
$class = sanitize_title( $class );
$classes = self::get_tax_class_slugs();
if ( ! in_array( $class, $classes ) ) {
$class = '';
}
return ( 'standard' === $class ) ? '' : $class;

View File

@ -99,10 +99,10 @@ class WC_Template_Loader {
if ( is_product_taxonomy() ) {
$term = get_queried_object();
$find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = 'taxonomy-' . $term->taxonomy . '.php';
$find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php';
$search_files[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$search_files[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$search_files[] = 'taxonomy-' . $term->taxonomy . '.php';
$search_files[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php';
}
$search_files[] = $default_file;

View File

@ -139,12 +139,12 @@ class WC_Webhook {
$should_deliver = false;
} elseif ( in_array( $current_action, array( 'delete_post', 'wp_trash_post' ), true ) ) {
// Only deliver deleted event for coupons, orders, and products.
if ( ! in_array( $GLOBALS['post_type'], array( 'shop_coupon', 'shop_order', 'product' ) ) ) {
if ( isset( $GLOBALS['post_type'] ) && ! in_array( $GLOBALS['post_type'], array( 'shop_coupon', 'shop_order', 'product' ) ) ) {
$should_deliver = false;
}
// Check if is delivering for the correct resource.
if ( str_replace( 'shop_', '', $GLOBALS['post_type'] ) !== $this->get_resource() ) {
if ( isset( $GLOBALS['post_type'] ) && str_replace( 'shop_', '', $GLOBALS['post_type'] ) !== $this->get_resource() ) {
$should_deliver = false;
}
} elseif ( 'delete_user' == $current_action ) {

View File

@ -68,7 +68,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
if ( $id && ! is_wp_error( $id ) ) {
$order->set_id( $id );
$this->update_post_meta( $order, true );
$this->update_post_meta( $order );
$order->save_meta_data();
$order->apply_changes();
$this->clear_caches( $order );
@ -205,12 +205,10 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
* Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
*
* @param WC_Order
* @param bool $force Force all props to be written even if not changed. This is used during creation.
* @since 2.7.0
*/
protected function update_post_meta( &$order, $force = false ) {
protected function update_post_meta( &$order ) {
$updated_props = array();
$changed_props = array_keys( $order->get_changes() );
$meta_key_to_props = array(
'_order_currency' => 'currency',
'_cart_discount' => 'discount_total',
@ -222,22 +220,17 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
'_order_version' => 'version',
'_prices_include_tax' => 'prices_include_tax',
);
foreach ( $meta_key_to_props as $meta_key => $prop ) {
if ( ! in_array( $prop, $changed_props ) && ! $force ) {
continue;
}
$value = $order->{"get_$prop"}( 'edit' );
if ( '' !== $value ) {
$updated = update_post_meta( $order->get_id(), $meta_key, $value );
} else {
$updated = delete_post_meta( $order->get_id(), $meta_key );
}
$props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );
foreach ( $props_to_update as $meta_key => $prop ) {
$value = $order->{"get_$prop"}( 'edit' );
$updated = update_post_meta( $order->get_id(), $meta_key, $value );
if ( $updated ) {
$updated_props[] = $prop;
}
}
do_action( 'woocommerce_order_object_updated_props', $order, $updated_props );
}
/**

View File

@ -69,7 +69,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
if ( $coupon_id ) {
$coupon->set_id( $coupon_id );
$this->update_post_meta( $coupon, true );
$this->update_post_meta( $coupon );
$coupon->save_meta_data();
$coupon->apply_changes();
do_action( 'woocommerce_new_coupon', $coupon_id );
@ -166,13 +166,10 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
* Helper method that updates all the post meta for a coupon based on it's settings in the WC_Coupon class.
*
* @param WC_Coupon
* @param bool $force Force all props to be written even if not changed. This is used during creation.
* @since 2.7.0
*/
private function update_post_meta( &$coupon, $force = false ) {
private function update_post_meta( &$coupon ) {
$updated_props = array();
$changed_props = array_keys( $coupon->get_changes() );
$meta_key_to_props = array(
'discount_type' => 'discount_type',
'coupon_amount' => 'amount',
@ -193,10 +190,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
'customer_email' => 'email_restrictions',
);
foreach ( $meta_key_to_props as $meta_key => $prop ) {
if ( ! in_array( $prop, $changed_props ) && ! $force ) {
continue;
}
$props_to_update = $this->get_props_to_update( $coupon, $meta_key_to_props );
foreach ( $props_to_update as $meta_key => $prop ) {
$value = $coupon->{"get_$prop"}( 'edit' );
switch ( $prop ) {
case 'individual_use' :
@ -223,6 +218,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
$updated_props[] = $prop;
}
}
do_action( 'woocommerce_coupon_object_updated_props', $coupon, $updated_props );
}
/**

View File

@ -257,6 +257,8 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
$updated_props[] = $prop;
}
}
do_action( 'woocommerce_customer_object_updated_props', $customer, $updated_props );
}
/**

View File

@ -131,6 +131,7 @@ class WC_Data_Store_WP {
// Figure out our field names.
if ( 'user' === $this->meta_type ) {
$meta_id_field = 'umeta_id';
$table = $wpdb->usermeta;
}
if ( ! empty( $this->object_id_field_for_meta ) ) {
@ -164,4 +165,27 @@ class WC_Data_Store_WP {
return ! in_array( $meta->meta_key, $this->internal_meta_keys );
}
/**
* Gets a list of props and meta keys that need updated based on change state
* or if they are present in the database or not.
*
* @param WC_Data $object The WP_Data object (WC_Coupon for coupons, etc).
* @param array $meta_key_to_props A mapping of meta keys => prop names.
* @param string $meta_type The internal WP meta type (post, user, etc).
* @return array A mapping of meta keys => prop names, filtered by ones that should be updated.
*/
protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
$props_to_update = array();
$changed_props = $object->get_changes();
// Props should be updated if they are a part of the $changed array or don't exist yet.
foreach ( $meta_key_to_props as $meta_key => $prop ) {
if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
$props_to_update[ $meta_key ] = $prop;
}
}
return $props_to_update;
}
}

View File

@ -138,12 +138,10 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
* Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
*
* @param WC_Order
* @param bool $force Force all props to be written even if not changed. This is used during creation.
* @since 2.7.0
*/
protected function update_post_meta( &$order, $force = false ) {
protected function update_post_meta( &$order ) {
$updated_props = array();
$changed_props = $order->get_changes();
$meta_key_to_props = array(
'_order_key' => 'order_key',
'_customer_user' => 'customer_id',
@ -158,15 +156,11 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
'_cart_hash' => 'cart_hash',
);
foreach ( $meta_key_to_props as $meta_key => $prop ) {
if ( ! array_key_exists( $prop, $changed_props ) && ! $force ) {
continue;
}
$props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );
foreach ( $props_to_update as $meta_key => $prop ) {
$value = $order->{"get_$prop"}( 'edit' );
if ( '' !== $value ? update_post_meta( $order->get_id(), $meta_key, $value ) : delete_post_meta( $order->get_id(), $meta_key ) ) {
$updated_props[] = $prop;
}
update_post_meta( $order->get_id(), $meta_key, $value );
$updated_props[] = $prop;
}
$address_props = array(
@ -197,21 +191,16 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
);
foreach ( $address_props as $props_key => $props ) {
foreach ( $props as $meta_key => $prop ) {
$prop_key = substr( $prop, 8 );
if ( ! $force && ( ! isset( $changed_props[ $props_key ] ) || ! array_key_exists( $prop_key, $changed_props[ $props_key ] ) ) ) {
continue;
}
$props_to_update = $this->get_props_to_update( $order, $props );
foreach ( $props_to_update as $meta_key => $prop ) {
$value = $order->{"get_$prop"}( 'edit' );
if ( '' !== $value ? update_post_meta( $order->get_id(), $meta_key, $value ) : delete_post_meta( $order->get_id(), $meta_key ) ) {
$updated_props[] = $prop;
$updated_props[] = $props_key;
}
update_post_meta( $order->get_id(), $meta_key, $value );
$updated_props[] = $prop;
$updated_props[] = $props_key;
}
}
parent::update_post_meta( $order, $force );
parent::update_post_meta( $order );
// If address changed, store concatinated version to make searches faster.
if ( in_array( 'billing', $updated_props ) || ! metadata_exists( 'post', $order->get_id(), '_billing_address_index' ) ) {
@ -226,6 +215,8 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
$data_store = WC_Data_Store::load( 'customer-download' );
$data_store->update_user_by_order_id( $order->get_id(), $order->get_customer_id(), $order->get_billing_email() );
}
do_action( 'woocommerce_order_object_updated_props', $order, $updated_props );
}
/**

View File

@ -57,27 +57,24 @@ class WC_Order_Refund_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT im
* @param bool $force Force all props to be written even if not changed. This is used during creation.
* @since 2.7.0
*/
protected function update_post_meta( &$refund, $force = false ) {
parent::update_post_meta( $refund, $force );
protected function update_post_meta( &$refund ) {
parent::update_post_meta( $refund );
$updated_props = array();
$changed_props = $refund->get_changes();
$meta_key_to_props = array(
'_refund_amount' => 'amount',
'_refunded_by' => 'refunded_by',
'_refund_reason' => 'reason',
);
foreach ( $meta_key_to_props as $meta_key => $prop ) {
if ( ! array_key_exists( $prop, $changed_props ) && ! $force ) {
continue;
}
$props_to_update = $this->get_props_to_update( $refund, $meta_key_to_props );
foreach ( $props_to_update as $meta_key => $prop ) {
$value = $refund->{"get_$prop"}( 'edit' );
if ( '' !== $value ? update_post_meta( $refund->get_id(), $meta_key, $value ) : delete_post_meta( $refund->get_id(), $meta_key ) ) {
$updated_props[] = $prop;
}
update_post_meta( $refund->get_id(), $meta_key, $value );
$updated_props[] = $prop;
}
do_action( 'woocommerce_order_refund_object_updated_props', $refund, $updated_props );
}
/**

View File

@ -71,18 +71,23 @@ class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Payment
global $wpdb;
$payment_token_data = array(
'gateway_id' => $token->get_gateway_id( 'edit' ),
'token' => $token->get_token( 'edit' ),
'user_id' => $token->get_user_id( 'edit' ),
'type' => $token->get_type( 'edit' ),
);
$updated_props = array();
$payment_token_data = array();
$props = array( 'gateway_id', 'token', 'user_id', 'type' );
$changed_props = array_keys( $token->get_changes() );
$wpdb->update(
$wpdb->prefix . 'woocommerce_payment_tokens',
$payment_token_data,
array( 'token_id' => $token->get_id( 'edit' ) )
);
foreach ( $changed_props as $prop ) {
$updated_props[] = $prop;
$payment_token_data[ $prop ] = $token->{"get_" . $prop}( 'edit' );
}
if ( ! empty( $payment_token_data ) ) {
$wpdb->update(
$wpdb->prefix . 'woocommerce_payment_tokens',
$payment_token_data,
array( 'token_id' => $token->get_id( 'edit' ) )
);
}
$token->save_meta_data();
$token->apply_changes();
@ -92,6 +97,7 @@ class WC_Payment_Token_Data_Store extends WC_Data_Store_WP implements WC_Payment
WC_Payment_Tokens::set_users_default( $token->get_user_id(), $token->get_id() );
}
do_action( 'woocommerce_payment_token_object_updated_props', $token, $updated_props );
do_action( 'woocommerce_payment_token_updated', $token->get_id() );
}

View File

@ -91,7 +91,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
if ( $id && ! is_wp_error( $id ) ) {
$product->set_id( $id );
$this->update_post_meta( $product, true );
$this->update_post_meta( $product );
$this->update_terms( $product );
$this->update_visibility( $product );
$this->update_attributes( $product );
@ -136,6 +136,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
$this->read_downloads( $product );
$this->read_visibility( $product );
$this->read_product_data( $product );
$this->read_extra_data( $product );
$product->set_object_read( true );
}
@ -260,9 +261,15 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
'download_expiry' => get_post_meta( $id, '_download_expiry', true ),
'image_id' => get_post_thumbnail_id( $id ),
) );
}
// Gets extra data associated with the product.
// Like button text or product URL for external products.
/**
* Read extra data associated with the product, like button text or product URL for external products.
*
* @param WC_Product
* @since 2.7.0
*/
protected function read_extra_data( &$product ) {
foreach ( $product->get_extra_data_keys() as $key ) {
$function = 'set_' . $key;
if ( is_callable( array( $product, $function ) ) ) {
@ -360,12 +367,10 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
* Helper method that updates all the post meta for a product based on it's settings in the WC_Product class.
*
* @param WC_Product
* @param bool $force Force all props to be written even if not changed. This is used during creation.
* @since 2.7.0
*/
protected function update_post_meta( &$product, $force = false ) {
protected function update_post_meta( &$product ) {
$updated_props = array();
$changed_props = array_keys( $product->get_changes() );
$meta_key_to_props = array(
'_sku' => 'sku',
'_regular_price' => 'regular_price',
@ -399,10 +404,14 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
'_wc_review_count' => 'review_count',
);
foreach ( $meta_key_to_props as $meta_key => $prop ) {
if ( ! in_array( $prop, $changed_props ) && ! $force ) {
continue;
}
// Make sure to take extra data (like product url or text for external products) into account.
$extra_data_keys = $product->get_extra_data_keys();
foreach ( $extra_data_keys as $key ) {
$meta_key_to_props[ '_' . $key ] = $key;
}
$props_to_update = $this->get_props_to_update( $product, $meta_key_to_props );
foreach ( $props_to_update as $meta_key => $prop ) {
$value = $product->{"get_$prop"}( 'edit' );
switch ( $prop ) {
case 'virtual' :
@ -449,16 +458,22 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
do_action( $product->is_type( 'variation' ) ? 'woocommerce_variation_set_stock_status' : 'woocommerce_product_set_stock_status' , $product->get_id(), $product->get_stock_status(), $product );
}
// Update extra data associated with the product.
// Like button text or product URL for external products.
// Update extra data associated with the product like button text or product URL for external products.
if ( ! $this->extra_data_saved ) {
foreach ( $product->get_extra_data_keys() as $key ) {
foreach ( $extra_data_keys as $key ) {
if ( ! array_key_exists( $key, $props_to_update ) ) {
continue;
}
$function = 'get_' . $key;
if ( ( $force || in_array( $key, $changed_props ) ) && is_callable( array( $product, $function ) ) ) {
update_post_meta( $product->get_id(), '_' . $key, $product->{$function}( 'edit' ) );
if ( is_callable( array( $product, $function ) ) ) {
if ( update_post_meta( $product->get_id(), '_' . $key, $product->{$function}( 'edit' ) ) ) {
$updated_props[] = $key;
}
}
}
}
do_action( 'woocommerce_product_object_updated_props', $product, $updated_props );
}
/**

View File

@ -16,10 +16,9 @@ class WC_Product_Grouped_Data_Store_CPT extends WC_Product_Data_Store_CPT implem
* Helper method that updates all the post meta for a grouped product.
*
* @param WC_Product
* @param bool $force Force all props to be written even if not changed. This is used during creation.
* @since 2.7.0
*/
protected function update_post_meta( &$product, $force = false ) {
protected function update_post_meta( &$product ) {
if ( update_post_meta( $product->get_id(), '_children', $product->get_children( 'edit' ) ) ) {
$child_prices = array();
foreach ( $product->get_children( 'edit' ) as $child_id ) {
@ -39,7 +38,7 @@ class WC_Product_Grouped_Data_Store_CPT extends WC_Product_Data_Store_CPT implem
$this->extra_data_saved = true;
}
parent::update_post_meta( $product, $force );
parent::update_post_meta( $product );
}
/**

View File

@ -17,7 +17,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*
* @var array
*/
private $prices_array = array();
protected $prices_array = array();
/**
* Read product data.
@ -41,7 +41,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
* @param bool $force_read True to bypass the transient.
* @return array
*/
private function read_children( &$product, $force_read = false ) {
protected function read_children( &$product, $force_read = false ) {
$children_transient_name = 'wc_product_children_' . $product->get_id();
$children = get_transient( $children_transient_name );
@ -80,7 +80,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
* @param WC_Product
* @return array
*/
private function read_variation_attributes( &$product ) {
protected function read_variation_attributes( &$product ) {
global $wpdb;
$variation_attributes = array();
@ -143,7 +143,6 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
* @return array of prices
*/
public function read_price_data( &$product, $include_taxes = false ) {
global $wp_filter;
/**
* Transient name for storing prices for this product (note: Max transient length is 45)
@ -151,26 +150,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
$transient_name = 'wc_var_prices_' . $product->get_id();
/**
* Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters.
* DEVELOPERS should filter this hash if offering conditonal pricing to keep it unique.
* @var string
*/
$price_hash = $include_taxes ? array( get_option( 'woocommerce_tax_display_shop', 'excl' ), WC_Tax::get_rates() ) : array( false );
$filter_names = array( 'woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price' );
foreach ( $filter_names as $filter_name ) {
if ( ! empty( $wp_filter[ $filter_name ] ) ) {
$price_hash[ $filter_name ] = array();
foreach ( $wp_filter[ $filter_name ] as $priority => $callbacks ) {
$price_hash[ $filter_name ][] = array_values( wp_list_pluck( $callbacks, 'function' ) );
}
}
}
$price_hash[] = WC_Cache_Helper::get_transient_version( 'product' );
$price_hash = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $include_taxes ) ) );
$price_hash = $this->get_price_hash( $product, $include_taxes );
/**
* $this->prices_array is an array of values which may have been modified from what is stored in transients - this may not match $transient_cached_prices_array.
@ -247,6 +227,37 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
return $this->prices_array[ $price_hash ];
}
/**
* Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters.
* DEVELOPERS should filter this hash if offering conditonal pricing to keep it unique.
*
* @since 2.7.0
* @param WC_Product
* @param bool $include_taxes If taxes should be calculated or not.
* @return string
*/
protected function get_price_hash( &$product, $include_taxes = false ) {
global $wp_filter;
$price_hash = $include_taxes ? array( get_option( 'woocommerce_tax_display_shop', 'excl' ), WC_Tax::get_rates() ) : array( false );
$filter_names = array( 'woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price' );
foreach ( $filter_names as $filter_name ) {
if ( ! empty( $wp_filter[ $filter_name ] ) ) {
$price_hash[ $filter_name ] = array();
foreach ( $wp_filter[ $filter_name ] as $priority => $callbacks ) {
$price_hash[ $filter_name ][] = array_values( wp_list_pluck( $callbacks, 'function' ) );
}
}
}
$price_hash[] = WC_Cache_Helper::get_transient_version( 'product' );
$price_hash = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $include_taxes ) ) );
return $price_hash;
}
/**
* Does a child have a weight set?
*
@ -256,7 +267,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
public function child_has_weight( $product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
return $children ? $wpdb->get_var( "SELECT 1 FROM $wpdb->postmeta WHERE meta_key = '_weight' AND meta_value > 0 AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : false;
}
@ -269,7 +280,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
public function child_has_dimensions( $product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
return $children ? $wpdb->get_var( "SELECT 1 FROM $wpdb->postmeta WHERE meta_key IN ( '_length', '_width', '_height' ) AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : false;
}
@ -282,7 +293,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
public function child_is_in_stock( $product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
$oufofstock_children = $children ? $wpdb->get_var( "SELECT COUNT( post_id ) FROM $wpdb->postmeta WHERE meta_key = '_stock_status' AND meta_value = 'instock' AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : 0;
return $children > $oufofstock_children;
}
@ -350,7 +361,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
public function sync_price( &$product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
$prices = $children ? array_unique( $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_price' AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) ) : array();
delete_post_meta( $product->get_id(), '_price' );

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