Merge branch 'master' into feature/webhook-crud

This commit is contained in:
Claudio Sanches 2017-12-07 18:21:52 -02:00
commit 2f6f6112c2
80 changed files with 3112 additions and 2220 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -186,7 +186,6 @@
}
.addons-column-block-item {
display: flex;
border-top: 2px solid #f9f9f9;
flex-direction: row;
flex-wrap: wrap;
@ -225,6 +224,18 @@
float: left;
}
.addons-banner-block-item,
.addons-column-block-item {
display: none;
}
.addons-banner-block-item:nth-child(-n+3) {
display: block;
}
.addons-column-block-item:nth-of-type(-n+3) {
display: flex;
}
.addons-small-dark-block {
background-color: #54687d;
text-align: center;
@ -3467,105 +3478,6 @@ img.help_tip {
.wc_emails_wrapper {
padding: 0 15px 10px 0;
}
.woocommerce-thumbnail-cropping {
margin: 0 40px 1em 0;
padding: 0;
display:inline-block;
vertical-align: top;
input[type=radio] {
vertical-align: top;
margin-top: 2px;
}
label {
display: inline-block;
span.description {
margin-top: .5em;
display:block;
color: #999;
}
span.woocommerce-thumbnail-cropping-aspect-ratio {
margin-top: .5em;
display:block;
}
}
li {
margin: 5px 0 1.5em;
padding: 0;
}
}
.woocommerce-thumbnail-preview {
display:inline-block;
width: 320px;
vertical-align: top;
h4 {
margin-top: 0;
}
.woocommerce-thumbnail-preview-block {
text-align: center;
width: 100px;
margin: 0 10px 0 0;
float: left;
.woocommerce-thumbnail-preview-block__image {
width: 90px;
height: 90px;
border: 5px solid #fff;
background: #eee;
box-shadow: 0 1px 1px #ccc;
margin: 0 0 10px;
position: relative;
overflow: hidden;
&:before,
&:after {
content: "";
display: block;
width: 30px;
height: 30px;
background: rgba(0,0,0,.1);
position: absolute;
top: 50%;
left: 50%;
margin-left: -20px;
margin-top: -20px;
}
&:before {
margin-top: -10px;
margin-left: -10px;
background: rgba(0,0,0,.1);
}
}
.woocommerce-thumbnail-preview-block__text {
width: 50%;
background: #ddd;
margin: 0 auto 10px;
height: 6px;
}
.woocommerce-thumbnail-preview-block__button {
width: 30px;
height: 5px;
border: 8px solid #fff;
background: #ededed;
box-shadow: 0 0 0 1px #ddd;
margin: 0 auto;
border-radius: 2px;
}
&:nth-child(3) {
.woocommerce-thumbnail-preview-block__text {
width: 75%;
}
}
&:nth-child(4) {
.woocommerce-thumbnail-preview-block__text {
width: 35%;
}
}
}
.woocommerce-thumbnail-preview-block:last-child {
margin: 0;
}
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -145,6 +145,35 @@
}
}
ul.products {
&.columns-1 {
li.product {
width: 100%;
margin-right: 0;
}
}
&.columns-2 {
li.product {
width: 48%;
}
}
&.columns-3 {
li.product {
width: 30.75%;
}
}
&.columns-5 {
li.product {
width: 16.95%;
}
}
&.columns-6 {
li.product {
width: 13.5%;
}
}
}
&.columns-1 {
ul.products {
li.product {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -682,7 +682,6 @@ p.demo_store,
color: $secondarytext;
background-color: $secondary;
border: 0;
white-space: nowrap;
display: inline-block;
background-image: none;
box-shadow: none;
@ -762,7 +761,6 @@ p.demo_store,
a.added_to_cart {
padding-top: 0.5em;
white-space: nowrap;
display: inline-block;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -138,7 +138,7 @@ jQuery(function( $ ) {
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 csv_data = 'data:text/csv;charset=utf-8,\uFEFF';
var s, series_data, d;
if ( 'table' === export_format ) {

View File

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

View File

@ -124,43 +124,4 @@
$( this ).closest( 'td' ).find( 'select' ).trigger( 'change' );
return false;
});
// Thumbnail cropping option updates and preview.
$( '.woocommerce-thumbnail-cropping' )
.on( 'change input', 'input', function() {
var value = $( '.woocommerce-thumbnail-cropping input:checked' ).val(),
$preview_images = $( '.woocommerce-thumbnail-preview-block__image' );
if ( 'custom' === value ) {
var width_ratio = Math.max( parseInt( $( 'input[name="thumbnail_cropping_aspect_ratio_width"]' ).val(), 10 ), 1 ),
height_ratio = Math.max( parseInt( $( 'input[name="thumbnail_cropping_aspect_ratio_height"]' ).val(), 10 ), 1 ),
height = ( 90 / width_ratio ) * height_ratio;
$preview_images.animate( { height: height + 'px' }, 200 );
$( '.woocommerce-thumbnail-cropping-aspect-ratio' ).slideDown( 200 );
} else if ( 'uncropped' === value ) {
var heights = [ '120', '60', '80' ];
$preview_images.each( function( index, element ) {
var height = heights[ index ];
$( element ).animate( { height: height + 'px' }, 200 );
} );
$( '.woocommerce-thumbnail-cropping-aspect-ratio' ).hide();
} else {
$preview_images.animate( { height: '90px' }, 200 );
$( '.woocommerce-thumbnail-cropping-aspect-ratio' ).hide();
}
return false;
});
$( '.woocommerce-thumbnail-cropping' ).find( 'input' ).change();
})( jQuery );

View File

@ -1 +1 @@
!function(t){t("select#woocommerce_allowed_countries").change(function(){"specific"===t(this).val()?(t(this).closest("tr").next("tr").hide(),t(this).closest("tr").next().next("tr").show()):"all_except"===t(this).val()?(t(this).closest("tr").next("tr").show(),t(this).closest("tr").next().next("tr").hide()):(t(this).closest("tr").next("tr").hide(),t(this).closest("tr").next().next("tr").hide())}).change(),t("select#woocommerce_ship_to_countries").change(function(){"specific"===t(this).val()?t(this).closest("tr").next("tr").show():t(this).closest("tr").next("tr").hide()}).change(),t("input#woocommerce_manage_stock").change(function(){t(this).is(":checked")?t(this).closest("tbody").find(".manage_stock_field").closest("tr").show():t(this).closest("tbody").find(".manage_stock_field").closest("tr").hide()}).change(),t(".colorpick").iris({change:function(e,i){t(this).parent().find(".colorpickpreview").css({backgroundColor:i.color.toString()})},hide:!0,border:!0}).on("click focus",function(e){e.stopPropagation(),t(".iris-picker").hide(),t(this).closest("td").find(".iris-picker").show(),t(this).data("original-value",t(this).val())}).on("change",function(){t(this).is(".iris-error")&&(t(this).data("original-value").match(/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/)?t(this).val(t(this).data("original-value")).change():t(this).val("").change())}),t("body").on("click",function(){t(".iris-picker").hide()}),t(function(){var e=!1;t("input, textarea, select, checkbox").change(function(){e=!0}),t(".woo-nav-tab-wrapper a").click(function(){window.onbeforeunload=e?function(){return woocommerce_settings_params.i18n_nav_warning}:""}),t(".submit input").click(function(){window.onbeforeunload=""})}),t("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(e,i){return i.children().each(function(){t(this).width(t(this).width())}),i.css("left","0"),i},start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style")}}),t(".woocommerce").on("click",".select_all",function(){return t(this).closest("td").find("select option").attr("selected","selected"),t(this).closest("td").find("select").trigger("change"),!1}),t(".woocommerce").on("click",".select_none",function(){return t(this).closest("td").find("select option").removeAttr("selected"),t(this).closest("td").find("select").trigger("change"),!1}),t(".woocommerce-thumbnail-cropping").on("change input","input",function(){var e=t(".woocommerce-thumbnail-cropping input:checked").val(),i=t(".woocommerce-thumbnail-preview-block__image");if("custom"===e){var o=90/Math.max(parseInt(t('input[name="thumbnail_cropping_aspect_ratio_width"]').val(),10),1)*Math.max(parseInt(t('input[name="thumbnail_cropping_aspect_ratio_height"]').val(),10),1);i.animate({height:o+"px"},200),t(".woocommerce-thumbnail-cropping-aspect-ratio").slideDown(200)}else if("uncropped"===e){var c=["120","60","80"];i.each(function(e,i){var o=c[e];t(i).animate({height:o+"px"},200)}),t(".woocommerce-thumbnail-cropping-aspect-ratio").hide()}else i.animate({height:"90px"},200),t(".woocommerce-thumbnail-cropping-aspect-ratio").hide();return!1}),t(".woocommerce-thumbnail-cropping").find("input").change()}(jQuery);
!function(t){t("select#woocommerce_allowed_countries").change(function(){"specific"===t(this).val()?(t(this).closest("tr").next("tr").hide(),t(this).closest("tr").next().next("tr").show()):"all_except"===t(this).val()?(t(this).closest("tr").next("tr").show(),t(this).closest("tr").next().next("tr").hide()):(t(this).closest("tr").next("tr").hide(),t(this).closest("tr").next().next("tr").hide())}).change(),t("select#woocommerce_ship_to_countries").change(function(){"specific"===t(this).val()?t(this).closest("tr").next("tr").show():t(this).closest("tr").next("tr").hide()}).change(),t("input#woocommerce_manage_stock").change(function(){t(this).is(":checked")?t(this).closest("tbody").find(".manage_stock_field").closest("tr").show():t(this).closest("tbody").find(".manage_stock_field").closest("tr").hide()}).change(),t(".colorpick").iris({change:function(e,i){t(this).parent().find(".colorpickpreview").css({backgroundColor:i.color.toString()})},hide:!0,border:!0}).on("click focus",function(e){e.stopPropagation(),t(".iris-picker").hide(),t(this).closest("td").find(".iris-picker").show(),t(this).data("original-value",t(this).val())}).on("change",function(){t(this).is(".iris-error")&&(t(this).data("original-value").match(/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/)?t(this).val(t(this).data("original-value")).change():t(this).val("").change())}),t("body").on("click",function(){t(".iris-picker").hide()}),t(function(){var e=!1;t("input, textarea, select, checkbox").change(function(){e=!0}),t(".woo-nav-tab-wrapper a").click(function(){window.onbeforeunload=e?function(){return woocommerce_settings_params.i18n_nav_warning}:""}),t(".submit input").click(function(){window.onbeforeunload=""})}),t("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(e,i){return i.children().each(function(){t(this).width(t(this).width())}),i.css("left","0"),i},start:function(t,e){e.item.css("background-color","#f6f6f6")},stop:function(t,e){e.item.removeAttr("style")}}),t(".woocommerce").on("click",".select_all",function(){return t(this).closest("td").find("select option").attr("selected","selected"),t(this).closest("td").find("select").trigger("change"),!1}),t(".woocommerce").on("click",".select_none",function(){return t(this).closest("td").find("select option").removeAttr("selected"),t(this).closest("td").find("select").trigger("change"),!1})}(jQuery);

View File

@ -35,7 +35,7 @@
"phpcs -s -p --standard=./phpcs.ruleset.xml"
],
"phpcbf": [
"phpcs -p --standard=./phpcs.ruleset.xml"
"phpcbf -p --standard=./phpcs.ruleset.xml"
]
},
"extra": {

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
$states['JP'] = array(
'JP01' => __( 'Hokkaido-dō', 'woocommerce' ),
'JP01' => __( 'Hokkaido', 'woocommerce' ),
'JP02' => __( 'Aomori-ken', 'woocommerce' ),
'JP03' => __( 'Iwate-ken', 'woocommerce' ),
'JP04' => __( 'Miyagi-ken', 'woocommerce' ),

View File

@ -263,7 +263,7 @@ abstract class WC_Data {
*/
public function get_meta_data() {
$this->maybe_read_meta_data();
return array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) );
return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
}
/**

View File

@ -1366,9 +1366,14 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$this->add_item( $item );
}
// Save tax totals.
$this->set_shipping_tax( WC_Tax::round( array_sum( $shipping_taxes ) ) );
$this->set_cart_tax( WC_Tax::round( array_sum( $cart_taxes ) ) );
if ( 'yes' !== get_option( 'woocommerce_tax_round_at_subtotal' ) ) {
$this->set_shipping_tax( wc_round_tax_total( array_sum( array_map( 'wc_round_tax_total', $shipping_taxes ) ) ) );
$this->set_cart_tax( wc_round_tax_total( array_sum( array_map( 'wc_round_tax_total', $cart_taxes ) ) ) );
} else {
$this->set_shipping_tax( wc_round_tax_total( array_sum( $shipping_taxes ) ) );
$this->set_cart_tax( wc_round_tax_total( array_sum( $cart_taxes ) ) );
}
$this->save();
}
@ -1599,7 +1604,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
public function get_subtotal_to_display( $compound = false, $tax_display = '' ) {
$tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
$subtotal = 0;
if ( ! $compound ) {
foreach ( $this->get_items() as $item ) {
$subtotal += $item->get_subtotal();

View File

@ -1428,7 +1428,9 @@ class WC_Product extends WC_Abstract_Legacy_Product {
public function is_visible() {
$visible = 'visible' === $this->get_catalog_visibility() || ( is_search() && 'search' === $this->get_catalog_visibility() ) || ( ! is_search() && 'catalog' === $this->get_catalog_visibility() );
if ( 'publish' !== $this->get_status() && ! current_user_can( 'edit_post', $this->get_id() ) ) {
if ( 'trash' === $this->get_status() ) {
$visible = false;
} elseif ( 'publish' !== $this->get_status() && ! current_user_can( 'edit_post', $this->get_id() ) ) {
$visible = false;
}

View File

@ -274,4 +274,71 @@ abstract class WC_Widget extends WP_Widget {
}
}
}
/**
* Get current page URL with various filtering props supported by WC.
*
* @return string
*/
protected function get_page_base_url() {
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} elseif ( is_shop() ) {
$link = get_permalink( wc_get_page_id( 'shop' ) );
} elseif ( is_product_category() ) {
$link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
} elseif ( is_product_tag() ) {
$link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
} else {
$queried_object = get_queried_object();
$link = get_term_link( $queried_object->slug, $queried_object->taxonomy );
}
// Min/Max.
if ( isset( $_GET['min_price'] ) ) {
$link = add_query_arg( 'min_price', wc_clean( wp_unslash( $_GET['min_price'] ) ), $link );
}
if ( isset( $_GET['max_price'] ) ) {
$link = add_query_arg( 'max_price', wc_clean( wp_unslash( $_GET['max_price'] ) ), $link );
}
// Order by.
if ( isset( $_GET['orderby'] ) ) {
$link = add_query_arg( 'orderby', wc_clean( wp_unslash( $_GET['orderby'] ) ), $link );
}
/**
* Search Arg.
* To support quote characters, first they are decoded from &quot; entities, then URL encoded.
*/
if ( get_search_query() ) {
$link = add_query_arg( 's', rawurlencode( htmlspecialchars_decode( get_search_query() ) ), $link );
}
// Post Type Arg.
if ( isset( $_GET['post_type'] ) ) {
$link = add_query_arg( 'post_type', wc_clean( wp_unslash( $_GET['post_type'] ) ), $link );
}
// Min Rating Arg.
if ( isset( $_GET['rating_filter'] ) ) {
$link = add_query_arg( 'rating_filter', wc_clean( wp_unslash( $_GET['rating_filter'] ) ), $link );
}
// All current filters.
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) {
foreach ( $_chosen_attributes as $name => $data ) {
$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
if ( ! empty( $data['terms'] ) ) {
$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
}
if ( 'or' == $data['query_type'] ) {
$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
}
}
}
return $link;
}
}

View File

@ -24,7 +24,7 @@ class WC_Admin_Addons {
*/
public static function get_featured() {
if ( false === ( $featured = get_transient( 'wc_addons_featured' ) ) ) {
$raw_featured = wp_safe_remote_get( 'https://d3t0oesq8995hv.cloudfront.net/add-ons/featured.json', array( 'user-agent' => 'WooCommerce Addons Page' ) );
$raw_featured = wp_safe_remote_get( 'https://d3t0oesq8995hv.cloudfront.net/add-ons/featured-v2.json', array( 'user-agent' => 'WooCommerce Addons Page' ) );
if ( ! is_wp_error( $raw_featured ) ) {
$featured = json_decode( wp_remote_retrieve_body( $raw_featured ) );
if ( $featured ) {
@ -160,23 +160,25 @@ class WC_Admin_Addons {
<p><?php echo esc_html( $block->description ); ?></p>
<div class="addons-banner-block-items">
<?php foreach ( $block->items as $item ) : ?>
<div class="addons-banner-block-item">
<div class="addons-banner-block-item-icon">
<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
<?php if ( self::show_extension( $item ) ) : ?>
<div class="addons-banner-block-item">
<div class="addons-banner-block-item-icon">
<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
</div>
<div class="addons-banner-block-item-content">
<h3><?php echo esc_html( $item->title ); ?></h3>
<p><?php echo esc_html( $item->description ); ?></p>
<?php
self::output_button(
$item->href,
$item->button,
'addons-button-solid',
$item->plugin
);
?>
</div>
</div>
<div class="addons-banner-block-item-content">
<h3><?php echo esc_html( $item->title ); ?></h3>
<p><?php echo esc_html( $item->description ); ?></p>
<?php
self::output_button(
$item->href,
$item->button,
'addons-button-solid',
$item->plugin
);
?>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
@ -221,25 +223,25 @@ class WC_Admin_Addons {
<h1><?php echo esc_html( $block->title ); ?></h1>
<p><?php echo esc_html( $block->description ); ?></p>
<?php foreach ( $block->items as $item ) : ?>
<div class="addons-column-block-item">
<div class="addons-column-block-item-icon">
<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
<?php if ( self::show_extension( $item ) ) : ?>
<div class="addons-column-block-item">
<div class="addons-column-block-item-icon">
<img class="addons-img" src="<?php echo esc_url( $item->image ); ?>" />
</div>
<div class="addons-column-block-item-content">
<h2><?php echo esc_html( $item->title ); ?></h2>
<?php
self::output_button(
$item->href,
$item->button,
'addons-button-solid',
$item->plugin
);
?>
<p><?php echo esc_html( $item->description ); ?></p>
</div>
</div>
<div class="addons-column-block-item-content">
<h2><?php echo esc_html( $item->title ); ?></h2>
<?php
self::output_button(
$item->href,
$item->button,
'addons-button-solid',
$item->plugin
);
?>
<p><?php echo esc_html( $item->description ); ?></p>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
@ -506,4 +508,27 @@ class WC_Admin_Addons {
wp_safe_redirect( remove_query_arg( array( 'install-addon', '_wpnonce' ) ) );
exit;
}
/**
* Should an extension be shown on the featured page.
*
* @param object $item
* @return boolean
*/
public static function show_extension( $item ) {
$location = WC()->countries->get_base_country();
if ( isset( $item->geowhitelist ) && ! in_array( $location, $item->geowhitelist, true ) ) {
return false;
}
if ( isset( $item->geoblacklist ) && in_array( $location, $item->geoblacklist, true ) ) {
return false;
}
if ( is_plugin_active( $item->plugin ) ) {
return false;
}
return true;
}
}

View File

@ -92,7 +92,7 @@ class WC_Admin_Exporters {
* Serve the generated file.
*/
public function download_export_file() {
if ( isset( $_GET['action'], $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'], 'product-csv' ) && 'download_product_csv' === $_GET['action'] ) {
if ( isset( $_GET['action'], $_GET['nonce'] ) && wp_verify_nonce( wp_unslash( $_GET['nonce'] ), 'product-csv' ) && 'download_product_csv' === wp_unslash( $_GET['action'] ) ) { // WPCS: input var ok, sanitization ok.
include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' );
$exporter = new WC_Product_CSV_Exporter();
$exporter->export();
@ -111,23 +111,23 @@ class WC_Admin_Exporters {
include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' );
$step = absint( $_POST['step'] );
$step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; // WPCS: input var ok, sanitization ok.
$exporter = new WC_Product_CSV_Exporter();
if ( ! empty( $_POST['columns'] ) ) {
$exporter->set_column_names( $_POST['columns'] );
if ( ! empty( $_POST['columns'] ) ) { // WPCS: input var ok.
$exporter->set_column_names( wp_unslash( $_POST['columns'] ) ); // WPCS: input var ok, sanitization ok.
}
if ( ! empty( $_POST['selected_columns'] ) ) {
$exporter->set_columns_to_export( $_POST['selected_columns'] );
if ( ! empty( $_POST['selected_columns'] ) ) { // WPCS: input var ok.
$exporter->set_columns_to_export( wp_unslash( $_POST['selected_columns'] ) ); // WPCS: input var ok, sanitization ok.
}
if ( ! empty( $_POST['export_meta'] ) ) {
if ( ! empty( $_POST['export_meta'] ) ) { // WPCS: input var ok.
$exporter->enable_meta_export( true );
}
if ( ! empty( $_POST['export_types'] ) ) {
$exporter->set_product_types_to_export( $_POST['export_types'] );
if ( ! empty( $_POST['export_types'] ) ) { // WPCS: input var ok.
$exporter->set_product_types_to_export( wp_unslash( $_POST['export_types'] ) ); // WPCS: input var ok, sanitization ok.
}
$exporter->set_page( $step );

View File

@ -13,7 +13,9 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Admin_Permalink_Settings', false ) ) :
if ( class_exists( 'WC_Admin_Permalink_Settings', false ) ) {
return new WC_Admin_Permalink_Settings();
}
/**
* WC_Admin_Permalink_Settings Class.
@ -39,30 +41,28 @@ class WC_Admin_Permalink_Settings {
* Init our settings.
*/
public function settings_init() {
// Add a section to the permalinks page
add_settings_section( 'woocommerce-permalink', __( 'Product permalinks', 'woocommerce' ), array( $this, 'settings' ), 'permalink' );
// Add our settings
add_settings_field(
'woocommerce_product_category_slug', // id
__( 'Product category base', 'woocommerce' ), // setting title
array( $this, 'product_category_slug_input' ), // display callback
'permalink', // settings page
'optional' // settings section
'woocommerce_product_category_slug',
__( 'Product category base', 'woocommerce' ),
array( $this, 'product_category_slug_input' ),
'permalink',
'optional'
);
add_settings_field(
'woocommerce_product_tag_slug', // id
__( 'Product tag base', 'woocommerce' ), // setting title
array( $this, 'product_tag_slug_input' ), // display callback
'permalink', // settings page
'optional' // settings section
'woocommerce_product_tag_slug',
__( 'Product tag base', 'woocommerce' ),
array( $this, 'product_tag_slug_input' ),
'permalink',
'optional'
);
add_settings_field(
'woocommerce_product_attribute_slug', // id
__( 'Product attribute base', 'woocommerce' ), // setting title
array( $this, 'product_attribute_slug_input' ), // display callback
'permalink', // settings page
'optional' // settings section
'woocommerce_product_attribute_slug',
__( 'Product attribute base', 'woocommerce' ),
array( $this, 'product_attribute_slug_input' ),
'permalink',
'optional'
);
$this->permalinks = wc_get_permalink_structure();
@ -99,9 +99,9 @@ class WC_Admin_Permalink_Settings {
* Show the settings.
*/
public function settings() {
echo wpautop( __( 'These settings control the permalinks used specifically for products.', 'woocommerce' ) );
/* translators: %s: Home URL */
echo wp_kses_post( wpautop( sprintf( __( 'If you like, you may enter custom structures for your product URLs here. For example, using <code>shop</code> would make your product links like <code>%sshop/sample-product/</code>. This setting affects product URLs only, not things such as product categories.', 'woocommerce' ), esc_url( home_url( '/' ) ) ) ) );
// Get shop page
$shop_page_id = wc_get_page_id( 'shop' );
$base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) );
$product_base = _x( 'product', 'default-slug', 'woocommerce' );
@ -115,28 +115,29 @@ class WC_Admin_Permalink_Settings {
<table class="form-table wc-permalink-structure">
<tbody>
<tr>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[0] ); ?>" class="wctog" <?php checked( $structures[0], $this->permalinks['product_base'] ); ?> /> <?php _e( 'Default', 'woocommerce' ); ?></label></th>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[0] ); ?>" class="wctog" <?php checked( $structures[0], $this->permalinks['product_base'] ); ?> /> <?php esc_html_e( 'Default', 'woocommerce' ); ?></label></th>
<td><code class="default-example"><?php echo esc_html( home_url() ); ?>/?product=sample-product</code> <code class="non-default-example"><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $product_base ); ?>/sample-product/</code></td>
</tr>
<?php if ( $shop_page_id ) : ?>
<tr>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" class="wctog" <?php checked( $structures[1], $this->permalinks['product_base'] ); ?> /> <?php _e( 'Shop base', 'woocommerce' ); ?></label></th>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" class="wctog" <?php checked( $structures[1], $this->permalinks['product_base'] ); ?> /> <?php esc_html_e( 'Shop base', 'woocommerce' ); ?></label></th>
<td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/sample-product/</code></td>
</tr>
<tr>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[2] ); ?>" class="wctog" <?php checked( $structures[2], $this->permalinks['product_base'] ); ?> /> <?php _e( 'Shop base with category', 'woocommerce' ); ?></label></th>
<th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[2] ); ?>" class="wctog" <?php checked( $structures[2], $this->permalinks['product_base'] ); ?> /> <?php esc_html_e( 'Shop base with category', 'woocommerce' ); ?></label></th>
<td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/product-category/sample-product/</code></td>
</tr>
<?php endif; ?>
<tr>
<th><label><input name="product_permalink" id="woocommerce_custom_selection" type="radio" value="custom" class="tog" <?php checked( in_array( $this->permalinks['product_base'], $structures ), false ); ?> />
<?php _e( 'Custom base', 'woocommerce' ); ?></label></th>
<th><label><input name="product_permalink" id="woocommerce_custom_selection" type="radio" value="custom" class="tog" <?php checked( in_array( $this->permalinks['product_base'], $structures, true ), false ); ?> />
<?php esc_html_e( 'Custom base', 'woocommerce' ); ?></label></th>
<td>
<input name="product_permalink_structure" id="woocommerce_permalink_structure" type="text" value="<?php echo esc_attr( $this->permalinks['product_base'] ? trailingslashit( $this->permalinks['product_base'] ) : '' ); ?>" class="regular-text code"> <span class="description"><?php _e( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default instead.', 'woocommerce' ); ?></span>
<input name="product_permalink_structure" id="woocommerce_permalink_structure" type="text" value="<?php echo esc_attr( $this->permalinks['product_base'] ? trailingslashit( $this->permalinks['product_base'] ) : '' ); ?>" class="regular-text code"> <span class="description"><?php esc_html_e( 'Enter a custom base to use. A base must be set or WordPress will use default instead.', 'woocommerce' ); ?></span>
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( 'wc-permalinks', 'wc-permalinks-nonce' ); ?>
<script type="text/javascript">
jQuery( function() {
jQuery('input.wctog').change(function() {
@ -171,20 +172,20 @@ class WC_Admin_Permalink_Settings {
}
// We need to save the options ourselves; settings api does not trigger save for the permalinks page.
if ( isset( $_POST['permalink_structure'] ) ) {
if ( isset( $_POST['permalink_structure'], $_POST['wc-permalinks-nonce'], $_POST['woocommerce_product_category_slug'], $_POST['woocommerce_product_tag_slug'], $_POST['woocommerce_product_attribute_slug'] ) && wp_verify_nonce( wp_unslash( $_POST['wc-permalinks-nonce'] ), 'wc-permalinks' ) ) { // WPCS: input var ok, sanitization ok.
wc_switch_to_site_locale();
$permalinks = (array) get_option( 'woocommerce_permalinks', array() );
$permalinks['category_base'] = wc_sanitize_permalink( trim( $_POST['woocommerce_product_category_slug'] ) );
$permalinks['tag_base'] = wc_sanitize_permalink( trim( $_POST['woocommerce_product_tag_slug'] ) );
$permalinks['attribute_base'] = wc_sanitize_permalink( trim( $_POST['woocommerce_product_attribute_slug'] ) );
$permalinks['category_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_category_slug'] ) ); // WPCS: input var ok, sanitization ok.
$permalinks['tag_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_tag_slug'] ) ); // WPCS: input var ok, sanitization ok.
$permalinks['attribute_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_attribute_slug'] ) ); // WPCS: input var ok, sanitization ok.
// Generate product base.
$product_base = isset( $_POST['product_permalink'] ) ? wc_clean( $_POST['product_permalink'] ) : '';
$product_base = isset( $_POST['product_permalink'] ) ? wc_clean( wp_unslash( $_POST['product_permalink'] ) ) : ''; // WPCS: input var ok, sanitization ok.
if ( 'custom' === $product_base ) {
if ( isset( $_POST['product_permalink_structure'] ) ) {
$product_base = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', trim( $_POST['product_permalink_structure'] ) ) );
if ( isset( $_POST['product_permalink_structure'] ) ) { // WPCS: input var ok.
$product_base = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', trim( wp_unslash( $_POST['product_permalink_structure'] ) ) ) ); // WPCS: input var ok, sanitization ok.
} else {
$product_base = '/';
}
@ -213,6 +214,4 @@ class WC_Admin_Permalink_Settings {
}
}
endif;
return new WC_Admin_Permalink_Settings();

View File

@ -82,10 +82,10 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
self::check_download_folder_protection();
// Clear any unwanted data and flush rules.
add_option( 'woocommerce_queue_flush_rewrite_rules', 'true' );
delete_transient( 'woocommerce_cache_excluded_uris' );
WC()->query->init_query_vars();
WC()->query->add_endpoints();
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
do_action( 'woocommerce_settings_saved' );
}
@ -192,7 +192,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
*
* Loops though the woocommerce options array and outputs each field.
*
* @param array $options Opens array to output.
* @param array[] $options Opens array to output.
*/
public static function output_fields( $options ) {
foreach ( $options as $value ) {
@ -530,64 +530,6 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
<?php
break;
// Thumbnail cropping setting. DEVELOPERS: This is private. Re-use at your own risk.
case 'thumbnail_cropping':
$option_value = self::get_option( $value['id'], $value['default'] );
if ( strstr( $option_value, ':' ) ) {
$cropping_split = explode( ':', $option_value );
$width = max( 1, current( $cropping_split ) );
$height = max( 1, end( $cropping_split ) );
} else {
$width = 4;
$height = 3;
}
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></th>
<td class="forminp">
<ul class="woocommerce-thumbnail-cropping">
<li>
<input type="radio" name="woocommerce_thumbnail_cropping" id="thumbnail_cropping_1_1" value="1:1" <?php checked( ! in_array( $option_value, array( '1:1', 'uncropped' ), true ), true ); ?> />
<label for="thumbnail_cropping_1_1">1:1<br/><span class="description"><?php esc_html_e( 'Images will be cropped into a square', 'woocommerce' ); ?></span></label>
</li>
<li>
<input type="radio" name="woocommerce_thumbnail_cropping" id="thumbnail_cropping_custom" value="custom" <?php checked( $option_value, 'custom' ); ?> />
<label for="thumbnail_cropping_custom">
<?php esc_html_e( 'Custom', 'woocommerce' ); ?><br/><span class="description"><?php esc_html_e( 'Images will be cropped to a custom aspect ratio', 'woocommerce' ); ?></span>
<span class="woocommerce-thumbnail-cropping-aspect-ratio">
<input name="thumbnail_cropping_aspect_ratio_width" type="text" pattern="\d*" size="3" value="<?php echo esc_attr( $width ); ?>" /> : <input name="thumbnail_cropping_aspect_ratio_height" type="text" pattern="\d*" size="3" value="<?php echo esc_attr( $height ); ?>" />
</span>
</label>
</li>
<li>
<input type="radio" name="woocommerce_thumbnail_cropping" id="thumbnail_cropping_uncropped" value="uncropped" <?php checked( $option_value, 'uncropped' ); ?> />
<label for="thumbnail_cropping_uncropped"><?php esc_html_e( 'Uncropped', 'woocommerce' ); ?><br/><span class="description"><?php esc_html_e( 'Images will display using the aspect ratio in which they were uploaded', 'woocommerce' ); ?></span></label>
</li>
</ul>
<div class="woocommerce-thumbnail-preview hide-if-no-js">
<h4><?php esc_html_e( 'Preview', 'woocommerce' ); ?></h4>
<div class="woocommerce-thumbnail-preview-block">
<div class="woocommerce-thumbnail-preview-block__image"></div>
<div class="woocommerce-thumbnail-preview-block__text"></div>
<div class="woocommerce-thumbnail-preview-block__button"></div>
</div>
<div class="woocommerce-thumbnail-preview-block">
<div class="woocommerce-thumbnail-preview-block__image"></div>
<div class="woocommerce-thumbnail-preview-block__text"></div>
<div class="woocommerce-thumbnail-preview-block__button"></div>
</div>
<div class="woocommerce-thumbnail-preview-block">
<div class="woocommerce-thumbnail-preview-block__image"></div>
<div class="woocommerce-thumbnail-preview-block__text"></div>
<div class="woocommerce-thumbnail-preview-block__button"></div>
</div>
</div>
</td>
</tr>
<?php
break;
// Single page selects.
case 'single_select_page':
$args = array(
@ -784,15 +726,6 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
$value['crop'] = $option['default']['crop'];
}
break;
case 'thumbnail_cropping':
$value = wc_clean( $raw_value );
if ( 'custom' === $value ) {
$width_ratio = isset( $_POST['thumbnail_cropping_aspect_ratio_width'] ) ? wc_clean( wp_unslash( $_POST['thumbnail_cropping_aspect_ratio_width'] ) ) : '1'; // WPCS: input var ok, CSRF ok.
$height_ratio = isset( $_POST['thumbnail_cropping_aspect_ratio_height'] ) ? wc_clean( wp_unslash( $_POST['thumbnail_cropping_aspect_ratio_height'] ) ) : '1'; // WPCS: input var ok, CSRF ok.
$value = $width_ratio . ':' . $height_ratio;
}
break;
case 'select':
$allowed_values = empty( $option['options'] ) ? array() : array_keys( $option['options'] );
if ( empty( $option['default'] ) && empty( $allowed_values ) ) {

View File

@ -135,9 +135,23 @@ class WC_Helper_Compat {
if ( is_plugin_active( 'woothemes-updater/woothemes-updater.php' ) ) {
deactivate_plugins( 'woothemes-updater/woothemes-updater.php' );
// Notify the user when the plugin is deactivated.
add_action( 'pre_current_active_plugins', array( __CLASS__, 'plugin_deactivation_notice' ) );
}
}
/**
* Display admin notice directing the user where to go.
*/
public static function plugin_deactivation_notice() {
?>
<div id="message" class="error is-dismissible">
<p><?php printf( __( 'The WooCommerce Helper plugin is no longer needed. <a href="%s">Manage subscriptions</a> from the extensions tab instead.', 'woocommerce' ), esc_url( admin_url( 'admin.php?page=wc-addons&section=helper' ) ) ); ?></p>
</div>
<?php
}
/**
* Register menu item.
*/

View File

@ -55,7 +55,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<td>
<input type="hidden" name="update_existing" value="0" />
<input type="checkbox" id="woocommerce-importer-update-existing" name="update_existing" value="1" />
<label for="woocommerce-importer-update-existing"><?php esc_html_e( 'If a product being imported matches an existing product by ID or SKU, update the existing product rather than creating a new product or skipping the row.', 'woocommerce' ); ?></label>
<label for="woocommerce-importer-update-existing"><?php esc_html_e( 'Existing products that match by ID or SKU will be updated. Products that do not exist will be skipped.', 'woocommerce' ); ?></label>
</td>
</tr>
<tr class="woocommerce-importer-advanced hidden">

View File

@ -258,7 +258,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
if ( $this->object->has_status( array( 'pending', 'on-hold' ) ) ) {
$actions['processing'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action = woocommerce_mark_order_status&status = processing&order_id = ' . $this->object->get_id() ), 'woocommerce-mark-order-status' ),
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=processing&order_id=' . $this->object->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Processing', 'woocommerce' ),
'action' => 'processing',
);
@ -266,7 +266,7 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
if ( $this->object->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
$actions['complete'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action = woocommerce_mark_order_status&status = completed&order_id = ' . $this->object->get_id() ), 'woocommerce-mark-order-status' ),
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=completed&order_id=' . $this->object->get_id() ), 'woocommerce-mark-order-status' ),
'name' => __( 'Complete', 'woocommerce' ),
'action' => 'complete',
);

View File

@ -1,4 +1,10 @@
<?php
/**
* Product data variations
*
* @package WooCommerce\Admin\Metaboxes\Views
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -19,24 +25,24 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="variations-defaults">
<strong><?php esc_html_e( 'Default Form Values', 'woocommerce' ); ?>: <?php echo wc_help_tip( __( 'These are the attributes that will be pre-selected on the frontend.', 'woocommerce' ) ); ?></strong>
<?php
foreach ( $variation_attributes as $attribute ) {
$selected_value = isset( $default_attributes[ sanitize_title( $attribute->get_name() ) ] ) ? $default_attributes[ sanitize_title( $attribute->get_name() ) ] : '';
?>
<select name="default_attribute_<?php echo sanitize_title( $attribute->get_name() ); ?>" data-current="<?php echo esc_attr( $selected_value ); ?>">
<?php /* translators: WooCommerce attribute label */ ?>
<option value=""><?php printf( esc_html__( 'No default %s&hellip;', 'woocommerce' ), wc_attribute_label( $attribute->get_name() ) ); ?></option>
<?php if ( $attribute->is_taxonomy() ) : ?>
<?php foreach ( $attribute->get_terms() as $option ) : ?>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ( $attribute->get_options() as $option ) : ?>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<?php
}
foreach ( $variation_attributes as $attribute ) {
$selected_value = isset( $default_attributes[ sanitize_title( $attribute->get_name() ) ] ) ? $default_attributes[ sanitize_title( $attribute->get_name() ) ] : '';
?>
<select name="default_attribute_<?php echo esc_attr( sanitize_title( $attribute->get_name() ) ); ?>" data-current="<?php echo esc_attr( $selected_value ); ?>">
<?php /* translators: WooCommerce attribute label */ ?>
<option value=""><?php esc_html( sprintf( __( 'No default %s&hellip;', 'woocommerce' ), wc_attribute_label( $attribute->get_name() ) ) ); ?></option>
<?php if ( $attribute->is_taxonomy() ) : ?>
<?php foreach ( $attribute->get_terms() as $option ) : ?>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ( $attribute->get_options() as $option ) : ?>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<?php
}
?>
</div>
<div class="clear"></div>
@ -62,11 +68,11 @@ if ( ! defined( 'ABSPATH' ) ) {
<option value="variable_sale_schedule"><?php esc_html_e( 'Set scheduled sale dates', 'woocommerce' ); ?></option>
</optgroup>
<optgroup label="<?php esc_attr_e( 'Inventory', 'woocommerce' ); ?>">
<option value="toggle_manage_stock"><?php _e( 'Toggle &quot;Manage stock&quot;', 'woocommerce' ); ?></option>
<option value="variable_stock"><?php _e( 'Stock', 'woocommerce' ); ?></option>
<option value="variable_stock_status_instock"><?php _e( 'Set Status - In stock', 'woocommerce' ); ?></option>
<option value="variable_stock_status_outofstock"><?php _e( 'Set Status - Out of stock', 'woocommerce' ); ?></option>
<option value="variable_stock_status_onbackorder"><?php _e( 'Set Status - On backorder', 'woocommerce' ); ?></option>
<option value="toggle_manage_stock"><?php esc_html_e( 'Toggle &quot;Manage stock&quot;', 'woocommerce' ); ?></option>
<option value="variable_stock"><?php esc_html_e( 'Stock', 'woocommerce' ); ?></option>
<option value="variable_stock_status_instock"><?php esc_html_e( 'Set Status - In stock', 'woocommerce' ); ?></option>
<option value="variable_stock_status_outofstock"><?php esc_html_e( 'Set Status - Out of stock', 'woocommerce' ); ?></option>
<option value="variable_stock_status_onbackorder"><?php esc_html_e( 'Set Status - On backorder', 'woocommerce' ); ?></option>
</optgroup>
<optgroup label="<?php esc_attr_e( 'Shipping', 'woocommerce' ); ?>">
<option value="variable_length"><?php esc_html_e( 'Length', 'woocommerce' ); ?></option>
@ -84,7 +90,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="variations-pagenav">
<?php /* translators: variations count */ ?>
<span class="displaying-num"><?php printf( esc_html( _n( '%s item', '%s items', $variations_count, 'woocommerce' ), $variations_count ) ); ?></span>
<span class="displaying-num"><?php echo esc_html( sprintf( _n( '%s item', '%s items', $variations_count, 'woocommerce' ), $variations_count ) ); ?></span>
<span class="expand-close">
(<a href="#" class="expand_all"><?php esc_html_e( 'Expand', 'woocommerce' ); ?></a> / <a href="#" class="close_all"><?php esc_html_e( 'Close', 'woocommerce' ); ?></a>)
</span>
@ -95,10 +101,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<label for="current-page-selector-1" class="screen-reader-text"><?php esc_html_e( 'Select Page', 'woocommerce' ); ?></label>
<select class="page-selector" id="current-page-selector-1" title="<?php esc_attr_e( 'Current page', 'woocommerce' ); ?>">
<?php for ( $i = 1; $i <= $variations_total_pages; $i++ ) : ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<option value="<?php echo $i; // WPCS: XSS ok. ?>"><?php echo $i; // WPCS: XSS ok. ?></option>
<?php endfor; ?>
</select>
<?php _ex( 'of', 'number of pages', 'woocommerce' ); ?> <span class="total-pages"><?php echo esc_html( $variations_total_pages ); ?></span>
<?php echo esc_html_x( 'of', 'number of pages', 'woocommerce' ); ?> <span class="total-pages"><?php echo esc_html( $variations_total_pages ); ?></span>
</span>
<a class="next-page" title="<?php esc_attr_e( 'Go to the next page', 'woocommerce' ); ?>" href="#">&rsaquo;</a>
<a class="last-page" title="<?php esc_attr_e( 'Go to the last page', 'woocommerce' ); ?>" href="#">&raquo;</a>
@ -107,10 +113,12 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="clear"></div>
</div>
<div class="woocommerce_variations wc-metaboxes" data-attributes="<?php
// esc_attr does not double encode - htmlspecialchars does
echo htmlspecialchars( wp_json_encode( wc_list_pluck( $variation_attributes, 'get_data' ) ) );
?>" data-total="<?php echo esc_attr( $variations_count ); ?>" data-total_pages="<?php echo esc_attr( $variations_total_pages ); ?>" data-page="1" data-edited="false">
<?php
// esc_attr does not double encode - htmlspecialchars does.
$attributes_data = htmlspecialchars( wp_json_encode( wc_list_pluck( $variation_attributes, 'get_data' ) ) );
?>
<div class="woocommerce_variations wc-metaboxes" data-attributes="<?php echo $attributes_data; // WPCS: XSS ok. ?>" data-total="<?php echo esc_attr( $variations_count ); ?>" data-total_pages="<?php echo esc_attr( $variations_total_pages ); ?>" data-page="1" data-edited="false">
</div>
<div class="toolbar">
@ -119,7 +127,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="variations-pagenav">
<?php /* translators: variations count*/ ?>
<span class="displaying-num"><?php printf( _n( '%s item', '%s items', $variations_count, 'woocommerce' ), $variations_count ); ?></span>
<span class="displaying-num"><?php echo esc_html( sprintf( _n( '%s item', '%s items', $variations_count, 'woocommerce' ), $variations_count ) ); ?></span>
<span class="expand-close">
(<a href="#" class="expand_all"><?php esc_html_e( 'Expand', 'woocommerce' ); ?></a> / <a href="#" class="close_all"><?php esc_html_e( 'Close', 'woocommerce' ); ?></a>)
</span>
@ -130,10 +138,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<label for="current-page-selector-1" class="screen-reader-text"><?php esc_html_e( 'Select Page', 'woocommerce' ); ?></label>
<select class="page-selector" id="current-page-selector-1" title="<?php esc_attr_e( 'Current page', 'woocommerce' ); ?>">
<?php for ( $i = 1; $i <= $variations_total_pages; $i++ ) : ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<option value="<?php echo $i; // WPCS: XSS ok. ?>"><?php echo $i; // WPCS: XSS ok. ?></option>
<?php endfor; ?>
</select>
<?php _ex( 'of', 'number of pages', 'woocommerce' ); ?> <span class="total-pages"><?php echo $variations_total_pages; ?></span>
<?php echo esc_html_x( 'of', 'number of pages', 'woocommerce' ); ?> <span class="total-pages"><?php echo esc_html( $variations_total_pages ); ?></span>
</span>
<a class="next-page" title="<?php esc_attr_e( 'Go to the next page', 'woocommerce' ); ?>" href="#">&rsaquo;</a>
<a class="last-page" title="<?php esc_attr_e( 'Go to the last page', 'woocommerce' ); ?>" href="#">&raquo;</a>

View File

@ -183,24 +183,6 @@ class WC_Settings_General extends WC_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Store notice', 'woocommerce' ),
'desc' => __( 'Enable site-wide store notice text', 'woocommerce' ),
'id' => 'woocommerce_demo_store',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Store notice text', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_demo_store_notice',
'default' => __( 'This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'woocommerce' ),
'type' => 'textarea',
'css' => 'width:350px; height: 65px;',
'autoload' => false,
),
array( 'type' => 'sectionend', 'id' => 'general_options' ),
array( 'title' => __( 'Currency options', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'The following options affect how prices are displayed on the frontend.', 'woocommerce' ), 'id' => 'pricing_options' ),

View File

@ -39,7 +39,6 @@ class WC_Settings_Products extends WC_Settings_Page {
public function get_sections() {
$sections = array(
'' => __( 'General', 'woocommerce' ),
'display' => __( 'Display', 'woocommerce' ),
'inventory' => __( 'Inventory', 'woocommerce' ),
'downloadable' => __( 'Downloadable products', 'woocommerce' ),
);
@ -75,155 +74,7 @@ class WC_Settings_Products extends WC_Settings_Page {
* @return array
*/
public function get_settings( $current_section = '' ) {
if ( 'display' === $current_section ) {
$settings = array(
array(
'title' => __( 'Shop &amp; product pages', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'catalog_options',
),
array(
'title' => __( 'Shop page', 'woocommerce' ),
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
'id' => 'woocommerce_shop_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
),
array(
'title' => __( 'Shop page display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ),
'id' => 'woocommerce_shop_page_display',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show categories', 'woocommerce' ),
'both' => __( 'Show categories &amp; products', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Default category display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ),
'id' => 'woocommerce_category_archive_display',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show subcategories', 'woocommerce' ),
'both' => __( 'Show subcategories &amp; products', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Default product sorting', 'woocommerce' ),
'desc' => __( 'This controls the default sort order of the catalog.', 'woocommerce' ),
'id' => 'woocommerce_default_catalog_orderby',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'menu_order',
'type' => 'select',
'options' => apply_filters( 'woocommerce_default_catalog_orderby_options', array(
'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ),
'popularity' => __( 'Popularity (sales)', 'woocommerce' ),
'rating' => __( 'Average rating', 'woocommerce' ),
'date' => __( 'Sort by most recent', 'woocommerce' ),
'price' => __( 'Sort by price (asc)', 'woocommerce' ),
'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ),
) ),
'desc_tip' => true,
),
array(
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
'id' => 'woocommerce_cart_redirect_after_add',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
'id' => 'woocommerce_enable_ajax_add_to_cart',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'type' => 'sectionend',
'id' => 'catalog_options',
),
);
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
$image_settings = array(
array(
'title' => __( 'Product images', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'These settings change how product images are displayed in your catalog.', 'woocommerce' ),
'id' => 'image_options',
),
'single_image_width' => array(
'title' => __( 'Main image width', 'woocommerce' ),
'desc' => __( 'This is the width used by the main image on single product pages. These images will be uncropped.', 'woocommerce' ),
'id' => 'woocommerce_single_image_width',
'css' => '',
'type' => 'text',
'custom_attributes' => array(
'size' => 3,
),
'suffix' => 'px',
'default' => 600,
'desc_tip' => true,
),
'thumbnail_image_width' => array(
'title' => __( 'Thumbnail width', 'woocommerce' ),
'desc' => __( 'This size is used for product archives and product listings.', 'woocommerce' ),
'id' => 'woocommerce_thumbnail_image_width',
'css' => '',
'type' => 'text',
'custom_attributes' => array(
'size' => 3,
),
'suffix' => 'px',
'default' => 300,
'desc_tip' => true,
),
array(
'title' => __( 'Thumbnail cropping', 'woocommerce' ),
'desc' => __( 'This determines how thumbnails appear. Widths will be fixed, whilst heights may vary.', 'woocommerce' ),
'id' => 'woocommerce_thumbnail_cropping',
'css' => '',
'type' => 'thumbnail_cropping',
'default' => '1:1',
'desc_tip' => false,
),
array(
'type' => 'sectionend',
'id' => 'image_options',
),
);
if ( isset( $theme_support['single_image_width'] ) ) {
unset( $image_settings['single_image_width'] );
}
if ( isset( $theme_support['thumbnail_image_width'] ) ) {
unset( $image_settings['thumbnail_image_width'] );
}
$settings = apply_filters( 'woocommerce_product_settings', array_merge( $settings, $image_settings ) );
} elseif ( 'inventory' === $current_section ) {
if ( 'inventory' === $current_section ) {
$settings = apply_filters( 'woocommerce_inventory_settings', array(
array(
@ -411,7 +262,91 @@ class WC_Settings_Products extends WC_Settings_Page {
));
} else {
$settings = apply_filters( 'woocommerce_products_general_settings', array(
$settings = apply_filters( 'woocommerce_product_settings', apply_filters( 'woocommerce_products_general_settings', array(
array(
'title' => __( 'Shop pages', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'catalog_options',
),
array(
'title' => __( 'Shop page', 'woocommerce' ),
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
'id' => 'woocommerce_shop_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
),
array(
'title' => __( 'Shop page display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on the product archive.', 'woocommerce' ),
'id' => 'woocommerce_shop_page_display',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show categories', 'woocommerce' ),
'both' => __( 'Show categories &amp; products', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Default category display', 'woocommerce' ),
'desc' => __( 'This controls what is shown on category archives.', 'woocommerce' ),
'id' => 'woocommerce_category_archive_display',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'woocommerce' ),
'subcategories' => __( 'Show subcategories', 'woocommerce' ),
'both' => __( 'Show subcategories &amp; products', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Default product sorting', 'woocommerce' ),
'desc' => __( 'This controls the default sort order of the catalog.', 'woocommerce' ),
'id' => 'woocommerce_default_catalog_orderby',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'menu_order',
'type' => 'select',
'options' => apply_filters( 'woocommerce_default_catalog_orderby_options', array(
'menu_order' => __( 'Default sorting (custom ordering + name)', 'woocommerce' ),
'popularity' => __( 'Popularity (sales)', 'woocommerce' ),
'rating' => __( 'Average rating', 'woocommerce' ),
'date' => __( 'Sort by most recent', 'woocommerce' ),
'price' => __( 'Sort by price (asc)', 'woocommerce' ),
'price-desc' => __( 'Sort by price (desc)', 'woocommerce' ),
) ),
'desc_tip' => true,
),
array(
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
'id' => 'woocommerce_cart_redirect_after_add',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
'id' => 'woocommerce_enable_ajax_add_to_cart',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'type' => 'sectionend',
'id' => 'catalog_options',
),
array(
'title' => __( 'Measurements', 'woocommerce' ),
'type' => 'title',
@ -520,7 +455,7 @@ class WC_Settings_Products extends WC_Settings_Page {
'id' => 'product_rating_options',
),
));
) ) );
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );

View File

@ -71,11 +71,14 @@ final class WC_Cart_Session {
$this->cart->set_coupon_discount_tax_totals( WC()->session->get( 'coupon_discount_tax_totals', array() ) );
$this->cart->set_removed_cart_contents( WC()->session->get( 'removed_cart_contents', array() ) );
if ( is_null( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) {
if ( is_null( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) { // @codingStandardsIgnoreLine
$cart = $saved_cart['cart'];
$update_cart_session = true;
} elseif ( is_null( $cart ) ) {
$cart = array();
} elseif ( is_array( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ) ) { // @codingStandardsIgnoreLine
$cart = array_merge( $saved_cart['cart'], $cart );
$update_cart_session = true;
}
if ( is_array( $cart ) ) {
@ -97,7 +100,9 @@ final class WC_Cart_Session {
} else {
// Put session data into array. Run through filter so other plugins can load their own session data.
$session_data = array_merge( $values, array( 'data' => $product ) );
$session_data = array_merge( $values, array(
'data' => $product,
) );
$cart_contents[ $key ] = apply_filters( 'woocommerce_get_cart_item_from_session', $session_data, $values, $key );
// Add to cart right away so the product is visible in woocommerce_get_cart_item_from_session hook.
@ -180,7 +185,9 @@ final class WC_Cart_Session {
*/
public function persistent_cart_update() {
if ( get_current_user_id() ) {
update_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), array( 'cart' => $this->get_cart_for_session() ) );
update_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), array(
'cart' => $this->get_cart_for_session(),
) );
}
}

View File

@ -5,6 +5,10 @@
* Methods are protected and class is final to keep this as an internal API.
* May be opened in the future once structure is stable.
*
* Rounding guide:
* - if something is being stored e.g. item total, store unrounded. This is so taxes can be recalculated later accurately.
* - if calculating a total, round (if settings allow).
*
* @author Automattic
* @package WooCommerce/Classes
*/
@ -315,12 +319,7 @@ final class WC_Cart_Totals {
}
$fee->taxes = apply_filters( 'woocommerce_cart_totals_get_fees_from_cart_taxes', $fee->taxes, $fee, $this );
$fee->total_tax = array_sum( $fee->taxes );
if ( ! $this->round_at_subtotal() ) {
$fee->total_tax = wc_round_tax_total( $fee->total_tax, wc_get_rounding_precision() );
}
$fee->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $fee->taxes ) );
// Set totals within object.
$fee->object->total = wc_remove_number_precision_deep( $fee->total );
@ -350,11 +349,7 @@ final class WC_Cart_Totals {
$shipping_line->taxable = true;
$shipping_line->total = wc_add_number_precision_deep( $shipping_object->cost );
$shipping_line->taxes = wc_add_number_precision_deep( $shipping_object->taxes, false );
$shipping_line->total_tax = wc_add_number_precision_deep( array_sum( $shipping_object->taxes ), false );
if ( ! $this->round_at_subtotal() ) {
$shipping_line->total_tax = wc_round_tax_total( $shipping_line->total_tax, wc_get_rounding_precision() );
}
$shipping_line->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $shipping_line->taxes ) );
$this->shipping[ $key ] = $shipping_line;
}
@ -427,7 +422,7 @@ final class WC_Cart_Totals {
$base_tax_rates = WC_Tax::get_base_tax_rates( $item->product->get_tax_class( 'unfiltered' ) );
// Work out a new base price without the shop's base tax.
$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true, true );
$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true );
// Now we have a new item price (excluding TAX).
$item->price = absint( $item->price - array_sum( $taxes ) );
@ -454,8 +449,8 @@ final class WC_Cart_Totals {
if ( $item->tax_rates !== $base_tax_rates ) {
// Work out a new base price without the shop's base tax.
$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true, true );
$new_taxes = WC_Tax::calc_tax( $item->price - array_sum( $taxes ), $item->tax_rates, false, true );
$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true );
$new_taxes = WC_Tax::calc_tax( $item->price - array_sum( $taxes ), $item->tax_rates, false );
// Now we have a new item price.
$item->price = $item->price - array_sum( $taxes ) + array_sum( $new_taxes );
@ -575,7 +570,7 @@ final class WC_Cart_Totals {
if ( ! isset( $taxes[ $rate_id ] ) ) {
$taxes[ $rate_id ] = 0;
}
$taxes[ $rate_id ] += $rate;
$taxes[ $rate_id ] += $this->round_line_tax( $rate );
}
}
@ -636,15 +631,13 @@ final class WC_Cart_Totals {
}
if ( $this->calculate_tax && $item->product->is_taxable() ) {
$item->taxes = WC_Tax::calc_tax( $item->total, $item->tax_rates, $item->price_includes_tax );
$item->total_tax = array_sum( $item->taxes );
if ( ! $this->round_at_subtotal() ) {
$item->total_tax = wc_round_tax_total( $item->total_tax, wc_get_rounding_precision() );
}
$total_taxes = WC_Tax::calc_tax( $item->total, $item->tax_rates, $item->price_includes_tax );
$item->taxes = $total_taxes;
$item->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $item->taxes ) );
if ( $item->price_includes_tax ) {
$item->total = $item->total - $item->total_tax;
// Use unrounded taxes so we can re-calculate from the orders screen accurately later.
$item->total = $item->total - array_sum( $item->taxes );
}
}
@ -653,7 +646,7 @@ final class WC_Cart_Totals {
$this->cart->cart_contents[ $item_key ]['line_tax'] = wc_remove_number_precision( $item->total_tax );
}
$this->set_total( 'items_total', array_sum( array_values( wp_list_pluck( $this->items, 'total' ) ) ) );
$this->set_total( 'items_total', array_sum( array_map( 'round', array_values( wp_list_pluck( $this->items, 'total' ) ) ) ) );
$this->set_total( 'items_total_tax', array_sum( array_values( wp_list_pluck( $this->items, 'total_tax' ) ) ) );
$this->cart->set_cart_contents_total( $this->get_total( 'items_total' ) );
@ -690,14 +683,11 @@ final class WC_Cart_Totals {
if ( $this->calculate_tax && $item->product->is_taxable() ) {
$subtotal_taxes = WC_Tax::calc_tax( $item->subtotal, $item->tax_rates, $item->price_includes_tax );
$item->subtotal_tax = array_sum( $subtotal_taxes );
if ( ! $this->round_at_subtotal() ) {
$item->subtotal_tax = wc_round_tax_total( $item->subtotal_tax, wc_get_rounding_precision() );
}
$item->subtotal_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $subtotal_taxes ) );
if ( $item->price_includes_tax ) {
$item->subtotal = $item->subtotal - $item->subtotal_tax;
// Use unrounded taxes so we can re-calculate from the orders screen accurately later.
$item->subtotal = $item->subtotal - array_sum( $subtotal_taxes );
}
}
@ -705,7 +695,7 @@ final class WC_Cart_Totals {
$this->cart->cart_contents[ $item_key ]['line_subtotal'] = wc_remove_number_precision( $item->subtotal );
$this->cart->cart_contents[ $item_key ]['line_subtotal_tax'] = wc_remove_number_precision( $item->subtotal_tax );
}
$this->set_total( 'items_subtotal', array_sum( array_values( wp_list_pluck( $this->items, 'subtotal' ) ) ) );
$this->set_total( 'items_subtotal', array_sum( array_map( 'round', array_values( wp_list_pluck( $this->items, 'subtotal' ) ) ) ) );
$this->set_total( 'items_subtotal_tax', array_sum( array_values( wp_list_pluck( $this->items, 'subtotal_tax' ) ) ) );
$this->cart->set_subtotal( $this->get_total( 'items_subtotal' ) );
@ -816,7 +806,7 @@ final class WC_Cart_Totals {
* @since 3.2.0
*/
protected function calculate_totals() {
$this->set_total( 'total', round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_merged_taxes( true ) ) ) );
$this->set_total( 'total', round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_merged_taxes( true ) ), 0 ) );
$this->cart->set_total_tax( array_sum( $this->get_merged_taxes( false ) ) );
// Allow plugins to hook and alter totals before final total is calculated.
@ -827,4 +817,18 @@ final class WC_Cart_Totals {
// Allow plugins to filter the grand total, and sum the cart totals in case of modifications.
$this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) );
}
/**
* Apply rounding to an array of taxes before summing. Rounds to store DP setting, ignoring precision.
*
* @since 3.2.6
* @param float $value Tax value.
* @return float
*/
protected function round_line_tax( $value ) {
if ( ! $this->round_at_subtotal() ) {
$value = wc_round_tax_total( $value, 0 );
}
return $value;
}
}

View File

@ -430,7 +430,7 @@ class WC_Cart extends WC_Legacy_Cart {
* @param string $value Value to set.
*/
public function set_subtotal( $value ) {
$this->totals['subtotal'] = wc_format_decimal( $value );
$this->totals['subtotal'] = wc_format_decimal( $value, wc_get_price_decimals() );
}
/**
@ -460,7 +460,7 @@ class WC_Cart extends WC_Legacy_Cart {
* @param string $value Value to set.
*/
public function set_discount_tax( $value ) {
$this->totals['discount_tax'] = wc_format_decimal( $value );
$this->totals['discount_tax'] = wc_round_tax_total( $value );
}
/**
@ -470,7 +470,7 @@ class WC_Cart extends WC_Legacy_Cart {
* @param string $value Value to set.
*/
public function set_shipping_total( $value ) {
$this->totals['shipping_total'] = wc_format_decimal( $value );
$this->totals['shipping_total'] = wc_format_decimal( $value, wc_get_price_decimals() );
}
/**
@ -490,7 +490,7 @@ class WC_Cart extends WC_Legacy_Cart {
* @param string $value Value to set.
*/
public function set_cart_contents_total( $value ) {
$this->totals['cart_contents_total'] = wc_format_decimal( $value );
$this->totals['cart_contents_total'] = wc_format_decimal( $value, wc_get_price_decimals() );
}
/**
@ -510,7 +510,7 @@ class WC_Cart extends WC_Legacy_Cart {
* @param string $value Value to set.
*/
public function set_total( $value ) {
$this->totals['total'] = wc_format_decimal( $value );
$this->totals['total'] = wc_format_decimal( $value, wc_get_price_decimals() );
}
/**
@ -530,7 +530,7 @@ class WC_Cart extends WC_Legacy_Cart {
* @param string $value Value to set.
*/
public function set_fee_total( $value ) {
$this->totals['fee_total'] = wc_format_decimal( $value );
$this->totals['fee_total'] = wc_format_decimal( $value, wc_get_price_decimals() );
}
/**

View File

@ -85,7 +85,7 @@ class WC_Discounts {
$item->object = $cart_item;
$item->product = $cart_item['data'];
$item->quantity = $cart_item['quantity'];
$item->price = wc_add_number_precision_deep( $item->product->get_price() ) * $item->quantity;
$item->price = wc_add_number_precision_deep( $item->product->get_price() * $item->quantity );
$this->items[ $key ] = $item;
}
@ -370,7 +370,7 @@ class WC_Discounts {
}
}
$discount = min( $discounted_price, $discount );
$discount = wc_cart_round_discount( min( $discounted_price, $discount ), 0 );
$cart_total = $cart_total + $price_to_discount;
$total_discount = $total_discount + $discount;
$applied_count = $applied_count + $apply_quantity;

View File

@ -99,6 +99,7 @@ class WC_Install {
'wc_update_330_webhooks',
'wc_update_330_product_stock_status',
'wc_update_330_set_default_product_cat',
'wc_update_330_clear_transients',
'wc_update_330_db_version',
),
);

2
includes/class-wc-order.php Normal file → Executable file
View File

@ -1381,7 +1381,7 @@ class WC_Order extends WC_Abstract_Order {
}
}
return $downloads;
return apply_filters( 'woocommerce_order_get_downloadable_items', $downloads, $this );
}
/**

View File

@ -256,6 +256,14 @@ class WC_Post_types {
$supports[] = 'comments';
}
$shop_page_id = wc_get_page_id( 'shop' );
if ( current_theme_supports( 'woocommerce' ) ) {
$has_archive = $shop_page_id && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop';
} else {
$has_archive = false;
}
register_post_type( 'product',
apply_filters( 'woocommerce_register_post_type_product',
array(
@ -296,7 +304,7 @@ class WC_Post_types {
'rewrite' => $permalinks['product_rewrite_slug'] ? array( 'slug' => $permalinks['product_rewrite_slug'], 'with_front' => false, 'feeds' => true ) : false,
'query_var' => true,
'supports' => $supports,
'has_archive' => ( $shop_page_id = wc_get_page_id( 'shop' ) ) && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop',
'has_archive' => $has_archive,
'show_in_nav_menus' => true,
'show_in_rest' => true,
)

View File

@ -74,11 +74,11 @@ class WC_Product_Variable extends WC_Product {
/**
* Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
*
* @param bool $include_taxes Should taxes be included in the prices.
* @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
* @return array Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
*/
public function get_variation_prices( $include_taxes = false ) {
$prices = $this->data_store->read_price_data( $this, $include_taxes );
public function get_variation_prices( $for_display = false ) {
$prices = $this->data_store->read_price_data( $this, $for_display );
foreach ( $prices as $price_key => $variation_prices ) {
$prices[ $price_key ] = $this->sort_variation_prices( $variation_prices );
@ -90,40 +90,40 @@ class WC_Product_Variable extends WC_Product {
/**
* Get the min or max variation regular price.
*
* @param string $min_or_max Min or max price.
* @param boolean $include_taxes Should the price include taxes?
* @param string $min_or_max Min or max price.
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
* @return string
*/
public function get_variation_regular_price( $min_or_max = 'min', $include_taxes = false ) {
$prices = $this->get_variation_prices( $include_taxes );
public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) {
$prices = $this->get_variation_prices( $for_display );
$price = 'min' === $min_or_max ? current( $prices['regular_price'] ) : end( $prices['regular_price'] );
return apply_filters( 'woocommerce_get_variation_regular_price', $price, $this, $min_or_max, $include_taxes );
return apply_filters( 'woocommerce_get_variation_regular_price', $price, $this, $min_or_max, $for_display );
}
/**
* Get the min or max variation sale price.
*
* @param string $min_or_max Min or max price.
* @param boolean $include_taxes Should the price include taxes?
* @param string $min_or_max Min or max price.
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
* @return string
*/
public function get_variation_sale_price( $min_or_max = 'min', $include_taxes = false ) {
$prices = $this->get_variation_prices( $include_taxes );
public function get_variation_sale_price( $min_or_max = 'min', $for_display = false ) {
$prices = $this->get_variation_prices( $for_display );
$price = 'min' === $min_or_max ? current( $prices['sale_price'] ) : end( $prices['sale_price'] );
return apply_filters( 'woocommerce_get_variation_sale_price', $price, $this, $min_or_max, $include_taxes );
return apply_filters( 'woocommerce_get_variation_sale_price', $price, $this, $min_or_max, $for_display );
}
/**
* Get the min or max variation (active) price.
*
* @param string $min_or_max Min or max price.
* @param boolean $include_taxes Should the price include taxes?
* @param string $min_or_max Min or max price.
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
* @return string
*/
public function get_variation_price( $min_or_max = 'min', $include_taxes = false ) {
$prices = $this->get_variation_prices( $include_taxes );
public function get_variation_price( $min_or_max = 'min', $for_display = false ) {
$prices = $this->get_variation_prices( $for_display );
$price = 'min' === $min_or_max ? current( $prices['price'] ) : end( $prices['price'] );
return apply_filters( 'woocommerce_get_variation_price', $price, $this, $min_or_max, $include_taxes );
return apply_filters( 'woocommerce_get_variation_price', $price, $this, $min_or_max, $for_display );
}
/**

View File

@ -23,6 +23,13 @@ class WC_Query {
*/
public $query_vars = array();
/**
* Reference to the main product query on the page.
*
* @var array
*/
private static $product_query;
/**
* Stores chosen attributes.
*
@ -64,9 +71,10 @@ class WC_Query {
public function init_query_vars() {
// Query vars to add to WP.
$this->query_vars = array(
'product-page' => '',
// Checkout actions.
'order-pay' => get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' ),
'order-received' => get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' ),
'order-pay' => get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' ),
'order-received' => get_option( 'woocommerce_checkout_order_received_endpoint', 'order-received' ),
// My account actions.
'orders' => get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ),
'view-order' => get_option( 'woocommerce_myaccount_view_order_endpoint', 'view-order' ),
@ -201,6 +209,7 @@ class WC_Query {
*/
public function get_current_endpoint() {
global $wp;
foreach ( $this->get_query_vars() as $key => $value ) {
if ( isset( $wp->query_vars[ $key ] ) ) {
return $key;
@ -334,17 +343,6 @@ class WC_Query {
$this->remove_product_query();
}
/**
* Search post excerpt.
*
* @deprecated 3.2.0 - Not needed anymore since WordPress 4.5.
* @param string $deprecated Deprecated.
*/
public function search_post_excerpt( $deprecated = '' ) {
wc_deprecated_function( 'WC_Query::search_post_excerpt', '3.2.0', 'Excerpt added to search query by default since WordPress 4.5.' );
return $deprecated;
}
/**
* WP SEO meta description.
*
@ -388,10 +386,15 @@ class WC_Query {
// Query vars that affect posts shown.
$q->set( 'meta_query', $this->get_meta_query( $q->get( 'meta_query' ), true ) );
$q->set( 'tax_query', $this->get_tax_query( $q->get( 'tax_query' ), true ) );
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ) );
$q->set( 'wc_query', 'product_query' );
$q->set( 'post__in', array_unique( (array) apply_filters( 'loop_shop_post_in', array() ) ) );
// Work out how many products to query.
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );
// Store reference to this query.
self::$product_query = $q;
do_action( 'woocommerce_product_query', $q, $this );
}
@ -412,27 +415,25 @@ class WC_Query {
remove_filter( 'posts_clauses', array( $this, 'order_by_rating_post_clauses' ) );
}
/**
* Remove the posts_where filter.
*
* @deprecated 3.2.0 - Nothing to remove anymore because search_post_excerpt() is deprecated.
*/
public function remove_posts_where() {
wc_deprecated_function( 'WC_Query::remove_posts_where', '3.2.0', 'Nothing to remove anymore because search_post_excerpt() is deprecated.' );
}
/**
* Returns an array of arguments for ordering products based on the selected values.
*
* @param string $orderby Order by.
* @param string $order Sorting order.
*
* @param string $orderby Order by param.
* @param string $order Order param.
* @return array
*/
public function get_catalog_ordering_args( $orderby = '', $order = '' ) {
// Get ordering from query string unless defined.
if ( ! $orderby ) {
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( (string) $_GET['orderby'] ) ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); // WPCS: input var ok, CSRF ok.
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( (string) wp_unslash( $_GET['orderby'] ) ) : ''; // WPCS: sanitization ok, input var ok.
if ( ! $orderby_value ) {
if ( is_search() ) {
$orderby_value = 'relevance';
} else {
$orderby_value = apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
}
}
// Get order + orderby args from string.
$orderby_value = explode( '-', $orderby_value );
@ -443,51 +444,51 @@ class WC_Query {
$orderby = strtolower( $orderby );
$order = strtoupper( $order );
$args = array(
'orderby' => 'relevance',
'order' => 'DESC',
'meta_key' => '', // WPCS: slow query ok.
'orderby' => $orderby,
'order' => ( 'DESC' === $order ) ? 'DESC' : 'ASC',
'meta_key' => '', // @codingStandardsIgnoreLine
);
// Set to default. Menu order for non-searches, relevance for searches.
if ( ! is_search() ) {
$args['orderby'] = 'menu_order title';
$args['order'] = ( 'DESC' === $order ) ? 'DESC' : 'ASC';
$args['meta_key'] = ''; // WPCS: slow query ok.
}
switch ( $orderby ) {
case 'rand':
$args['orderby'] = 'rand';
case 'menu_order' :
$args['orderby'] = 'menu_order title';
break;
case 'date':
case 'relevance' :
$args['orderby']= 'relevance';
$args['order'] = 'DESC';
break;
case 'rand' :
$args['orderby'] = 'rand'; // @codingStandardsIgnoreLine
break;
case 'date' :
$args['orderby'] = 'date ID';
$args['order'] = ( 'ASC' === $order ) ? 'ASC' : 'DESC';
break;
case 'price':
case 'price' :
if ( 'DESC' === $order ) {
add_filter( 'posts_clauses', array( $this, 'order_by_price_desc_post_clauses' ) );
} else {
add_filter( 'posts_clauses', array( $this, 'order_by_price_asc_post_clauses' ) );
}
break;
case 'popularity':
$args['meta_key'] = 'total_sales'; // WPCS: slow query ok.
case 'popularity' :
$args['meta_key'] = 'total_sales'; // @codingStandardsIgnoreLine
// Sorting handled later though a hook.
add_filter( 'posts_clauses', array( $this, 'order_by_popularity_post_clauses' ) );
break;
case 'rating':
$args['meta_key'] = '_wc_average_rating'; // WPCS: slow query ok.
case 'rating' :
$args['meta_key'] = '_wc_average_rating'; // @codingStandardsIgnoreLine
$args['orderby'] = array(
'meta_value_num' => 'DESC',
'ID' => 'ASC',
);
break;
case 'title':
case 'title' :
$args['orderby'] = 'title';
$args['order'] = ( 'DESC' === $order ) ? 'DESC' : 'ASC';
break;
case 'relevance':
case 'relevance' :
$args['orderby'] = 'relevance';
$args['order'] = 'DESC';
break;
@ -569,30 +570,6 @@ class WC_Query {
return $args;
}
/**
* Order by rating post clauses.
*
* @deprecated 3.0.0
* @param array $args Query args.
* @return array
*/
public function order_by_rating_post_clauses( $args ) {
global $wpdb;
wc_deprecated_function( 'order_by_rating_post_clauses', '3.0' );
$args['fields'] .= ", AVG( $wpdb->commentmeta.meta_value ) as average_rating ";
$args['where'] .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";
$args['join'] .= "
LEFT OUTER JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID)
LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)
";
$args['orderby'] = "average_rating DESC, $wpdb->posts.post_date DESC";
$args['groupby'] = "$wpdb->posts.ID";
return $args;
}
/**
* Appends meta queries to an array.
*
@ -692,35 +669,12 @@ class WC_Query {
}
/**
* Return a meta query for filtering by rating.
* Get the main query which product queries ran against.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @return array
*/
public function rating_filter_meta_query() {
return array();
}
/**
* Returns a meta query to handle product visibility.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @param string $compare Compare type.
* @return array
*/
public function visibility_meta_query( $compare = 'IN' ) {
return array();
}
/**
* Returns a meta query to handle product stock status.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @param string $status Status.
* @return array
*/
public function stock_status_meta_query( $status = 'instock' ) {
return array();
public static function get_main_query() {
return self::$product_query;
}
/**
@ -729,9 +683,7 @@ class WC_Query {
* @return array
*/
public static function get_main_tax_query() {
global $wp_the_query;
$tax_query = isset( $wp_the_query->tax_query, $wp_the_query->tax_query->queries ) ? $wp_the_query->tax_query->queries : array();
$tax_query = isset( self::$product_query->tax_query, self::$product_query->tax_query->queries ) ? self::$product_query->tax_query->queries : array();
return $tax_query;
}
@ -742,9 +694,7 @@ class WC_Query {
* @return array
*/
public static function get_main_meta_query() {
global $wp_the_query;
$args = $wp_the_query->query_vars;
$args = self::$product_query->query_vars;
$meta_query = isset( $args['meta_query'] ) ? $args['meta_query'] : array();
return $meta_query;
@ -754,9 +704,9 @@ class WC_Query {
* Based on WP_Query::parse_search
*/
public static function get_main_search_query_sql() {
global $wp_the_query, $wpdb;
global $wpdb;
$args = $wp_the_query->query_vars;
$args = self::$product_query->query_vars;
$search_terms = isset( $args['search_terms'] ) ? $args['search_terms'] : array();
$sql = array();
@ -774,7 +724,7 @@ class WC_Query {
}
$like = '%' . $wpdb->esc_like( $term ) . '%';
$sql[] = $wpdb->prepare( "(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like ); // WPCS: db call ok, cache ok, unprepared SQL ok.
$sql[] = $wpdb->prepare( "(($wpdb->posts.post_title $like_op %s) $andor_op ($wpdb->posts.post_excerpt $like_op %s) $andor_op ($wpdb->posts.post_content $like_op %s))", $like, $like, $like ); // unprepared SQL ok.
}
if ( ! empty( $sql ) && ! is_user_logged_in() ) {
@ -786,25 +736,22 @@ class WC_Query {
/**
* Layered Nav Init.
*
* @return array
*/
public static function get_layered_nav_chosen_attributes() {
if ( ! is_array( self::$_chosen_attributes ) ) {
self::$_chosen_attributes = array();
$attribute_taxonomies = wc_get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute = wc_sanitize_taxonomy_name( $tax->attribute_name );
$taxonomy = wc_attribute_taxonomy_name( $attribute );
$filter_terms = ! empty( $_GET[ 'filter_' . $attribute ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ 'filter_' . $attribute ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$filter_terms = ! empty( $_GET[ 'filter_' . $attribute ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ 'filter_' . $attribute ] ) ) ) : array(); // WPCS: sanitization ok, input var ok.
if ( empty( $filter_terms ) || ! taxonomy_exists( $taxonomy ) ) {
continue;
}
$query_type = ! empty( $_GET[ 'query_type_' . $attribute ] ) && in_array( wp_unslash( $_GET[ 'query_type_' . $attribute ] ), array( 'and', 'or' ), true ) ? wc_clean( wp_unslash( $_GET[ 'query_type_' . $attribute ] ) ) : ''; // WPCS: input var ok, CSRF ok.
$query_type = ! empty( $_GET[ 'query_type_' . $attribute ] ) && in_array( $_GET[ 'query_type_' . $attribute ], array( 'and', 'or' ), true ) ? wc_clean( wp_unslash( $_GET[ 'query_type_' . $attribute ] ) ) : ''; // WPCS: sanitization ok, input var ok.
self::$_chosen_attributes[ $taxonomy ]['terms'] = array_map( 'sanitize_title', $filter_terms ); // Ensures correct encoding.
self::$_chosen_attributes[ $taxonomy ]['query_type'] = $query_type ? $query_type : apply_filters( 'woocommerce_layered_nav_default_query_type', 'and' );
}
@ -813,6 +760,73 @@ class WC_Query {
return self::$_chosen_attributes;
}
/**
* Remove the add-to-cart param from pagination urls.
*
* @param string $url URL.
* @return string
*/
public function remove_add_to_cart_pagination( $url ) {
return remove_query_arg( 'add-to-cart', $url );
}
// @codingStandardsIgnoreStart
/**
* Order by rating post clauses.
*
* @deprecated 3.0.0
* @param array $args
* @return array
*/
public function order_by_rating_post_clauses( $args ) {
global $wpdb;
wc_deprecated_function( 'order_by_rating_post_clauses', '3.0' );
$args['fields'] .= ", AVG( $wpdb->commentmeta.meta_value ) as average_rating ";
$args['where'] .= " AND ( $wpdb->commentmeta.meta_key = 'rating' OR $wpdb->commentmeta.meta_key IS null ) ";
$args['join'] .= "
LEFT OUTER JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID)
LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)
";
$args['orderby'] = "average_rating DESC, $wpdb->posts.post_date DESC";
$args['groupby'] = "$wpdb->posts.ID";
return $args;
}
/**
* Return a meta query for filtering by rating.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @return array
*/
public function rating_filter_meta_query() {
return array();
}
/**
* Returns a meta query to handle product visibility.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @param string $compare (default: 'IN')
* @return array
*/
public function visibility_meta_query( $compare = 'IN' ) {
return array();
}
/**
* Returns a meta query to handle product stock status.
*
* @deprecated 3.0.0 Replaced with taxonomy.
* @param string $status (default: 'instock')
* @return array
*/
public function stock_status_meta_query( $status = 'instock' ) {
return array();
}
/**
* Layered nav init.
*
@ -843,12 +857,21 @@ class WC_Query {
}
/**
* Remove the add-to-cart param from pagination urls.
* Search post excerpt.
*
* @param string $url URL.
* @return string
* @deprecated 3.2.0 - Not needed anymore since WordPress 4.5.
*/
public function remove_add_to_cart_pagination( $url ) {
return remove_query_arg( 'add-to-cart', $url );
public function search_post_excerpt( $where = '' ) {
wc_deprecated_function( 'WC_Query::search_post_excerpt', '3.2.0', 'Excerpt added to search query by default since WordPress 4.5.' );
return $where;
}
/**
* Remove the posts_where filter.
* @deprecated 3.2.0 - Nothing to remove anymore because search_post_excerpt() is deprecated.
*/
public function remove_posts_where() {
wc_deprecated_function( 'WC_Query::remove_posts_where', '3.2.0', 'Nothing to remove anymore because search_post_excerpt() is deprecated.' );
}
// @codingStandardsIgnoreEnd
}

View File

@ -18,19 +18,19 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Session_Handler extends WC_Session {
/** @var string cookie name */
private $_cookie;
protected $_cookie;
/** @var string session due to expire timestamp */
private $_session_expiring;
protected $_session_expiring;
/** @var string session expiration timestamp */
private $_session_expiration;
protected $_session_expiration;
/** $var bool Bool based on whether a cookie exists **/
private $_has_cookie = false;
protected $_has_cookie = false;
/** @var string Custom session table name */
private $_table;
protected $_table;
/**
* Constructor for the session class.

View File

@ -1,25 +1,27 @@
<?php
/**
* Handles storage and retrieval of shipping zones
*
* @package WooCommerce/Classes
* @author Automattic
* @version 3.3.0
* @since 2.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles storage and retrieval of shipping zones
*
* @class WC_Shipping_Zones
* @since 2.6.0
* @version 3.0.0
* @package WooCommerce/Classes
* @category Class
* @author WooCommerce
* Shipping zones class.
*/
class WC_Shipping_Zones {
/**
* Get shipping zones from the database
* Get shipping zones from the database.
*
* @since 2.6.0
* @return array of arrays
* @return array Array of arrays.
*/
public static function get_zones() {
$data_store = WC_Data_Store::load( 'shipping-zone' );
@ -27,7 +29,7 @@ class WC_Shipping_Zones {
$zones = array();
foreach ( $raw_zones as $raw_zone ) {
$zone = new WC_Shipping_Zone( $raw_zone );
$zone = new WC_Shipping_Zone( $raw_zone );
$zones[ $zone->get_id() ] = $zone->get_data();
$zones[ $zone->get_id() ]['zone_id'] = $zone->get_id();
$zones[ $zone->get_id() ]['formatted_zone_location'] = $zone->get_formatted_location();
@ -39,8 +41,9 @@ class WC_Shipping_Zones {
/**
* Get shipping zone using it's ID
*
* @since 2.6.0
* @param int $zone_id
* @param int $zone_id Zone ID.
* @return WC_Shipping_Zone|bool
*/
public static function get_zone( $zone_id ) {
@ -49,20 +52,23 @@ class WC_Shipping_Zones {
/**
* Get shipping zone by an ID.
*
* @since 2.6.0
* @param string $by zone_id or instance_id
* @param int $id
* @param string $by Get by 'zone_id' or 'instance_id'.
* @param int $id ID.
* @return WC_Shipping_Zone|bool
*/
public static function get_zone_by( $by = 'zone_id', $id = 0 ) {
$zone_id = false;
switch ( $by ) {
case 'zone_id' :
case 'zone_id':
$zone_id = $id;
break;
case 'instance_id' :
break;
case 'instance_id':
$data_store = WC_Data_Store::load( 'shipping-zone' );
$zone_id = $data_store->get_zone_id_by_instance_id( $id );
break;
break;
}
if ( false !== $zone_id ) {
@ -77,11 +83,10 @@ class WC_Shipping_Zones {
}
/**
* Get shipping zone using it's ID
* Get shipping zone using it's ID.
*
* @since 2.6.0
*
* @param $instance_id
*
* @param int $instance_id Instance ID.
* @return bool|WC_Shipping_Method
*/
public static function get_shipping_method( $instance_id ) {
@ -102,7 +107,8 @@ class WC_Shipping_Zones {
/**
* Delete a zone using it's ID
* @param int $zone_id
*
* @param int $zone_id Zone ID.
* @since 2.6.0
*/
public static function delete_zone( $zone_id ) {
@ -112,9 +118,10 @@ class WC_Shipping_Zones {
/**
* Find a matching zone for a given package.
*
* @since 2.6.0
* @uses wc_make_numeric_postcode()
* @param object $package
* @param array $package Shipping package.
* @return WC_Shipping_Zone
*/
public static function get_zone_matching_package( $package ) {

View File

@ -278,8 +278,11 @@ class WC_Shipping {
/**
* See if package is shippable.
* @param array $package
* @return boolean
*
* Packages are shippable until proven otherwise e.g. after getting a shipping country.
*
* @param array $package Package of cart items.
* @return bool
*/
protected function is_package_shippable( $package ) {
@ -297,51 +300,52 @@ class WC_Shipping {
*
* Calculates each shipping methods cost. Rates are stored in the session based on the package hash to avoid re-calculation every page load.
*
* @param array $package cart items
* @param array $package Package of cart items.
* @param int $package_key Index of the package being calculated. Used to cache multiple package rates.
*
* @return array|bool
*/
public function calculate_shipping_for_package( $package = array(), $package_key = 0 ) {
if ( ! $this->enabled || empty( $package ) || ! $this->is_package_shippable( $package ) ) {
// If shipping is disabled or the package is invalid, return false.
if ( ! $this->enabled || empty( $package ) ) {
return false;
}
// Check if we need to recalculate shipping for this package
$package_to_hash = $package;
$package['rates'] = array();
// Remove data objects so hashes are consistent
foreach ( $package_to_hash['contents'] as $item_id => $item ) {
unset( $package_to_hash['contents'][ $item_id ]['data'] );
}
// If the package is not shippable, e.g. trying to ship to an invalid country, do not calculate rates.
if ( $this->is_package_shippable( $package ) ) {
// Check if we need to recalculate shipping for this package.
$package_to_hash = $package;
$package_hash = 'wc_ship_' . md5( json_encode( $package_to_hash ) . WC_Cache_Helper::get_transient_version( 'shipping' ) );
$session_key = 'shipping_for_package_' . $package_key;
$stored_rates = WC()->session->get( $session_key );
if ( ! is_array( $stored_rates ) || $package_hash !== $stored_rates['package_hash'] || 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) ) {
// Calculate shipping method rates
$package['rates'] = array();
foreach ( $this->load_shipping_methods( $package ) as $shipping_method ) {
// Shipping instances need an ID
if ( ! $shipping_method->supports( 'shipping-zones' ) || $shipping_method->get_instance_id() ) {
$package['rates'] = $package['rates'] + $shipping_method->get_rates_for_package( $package ); // + instead of array_merge maintains numeric keys
}
// Remove data objects so hashes are consistent.
foreach ( $package_to_hash['contents'] as $item_id => $item ) {
unset( $package_to_hash['contents'][ $item_id ]['data'] );
}
// Filter the calculated rates
$package['rates'] = apply_filters( 'woocommerce_package_rates', $package['rates'], $package );
$package_hash = 'wc_ship_' . md5( wp_json_encode( $package_to_hash ) . WC_Cache_Helper::get_transient_version( 'shipping' ) );
$session_key = 'shipping_for_package_' . $package_key;
$stored_rates = WC()->session->get( $session_key );
// Store in session to avoid recalculation
WC()->session->set( $session_key, array(
'package_hash' => $package_hash,
'rates' => $package['rates'],
) );
} else {
$package['rates'] = $stored_rates['rates'];
if ( ! is_array( $stored_rates ) || $package_hash !== $stored_rates['package_hash'] || 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) ) {
foreach ( $this->load_shipping_methods( $package ) as $shipping_method ) {
if ( ! $shipping_method->supports( 'shipping-zones' ) || $shipping_method->get_instance_id() ) {
$package['rates'] = $package['rates'] + $shipping_method->get_rates_for_package( $package ); // + instead of array_merge maintains numeric keys
}
}
// Filter the calculated rates.
$package['rates'] = apply_filters( 'woocommerce_package_rates', $package['rates'], $package );
// Store in session to avoid recalculation.
WC()->session->set( $session_key, array(
'package_hash' => $package_hash,
'rates' => $package['rates'],
) );
} else {
$package['rates'] = $stored_rates['rates'];
}
}
return $package;
}

View File

@ -151,8 +151,6 @@ class WC_Shortcodes {
* @return string
*/
public static function product_categories( $atts ) {
global $woocommerce_loop;
if ( isset( $atts['number'] ) ) {
$atts['limit'] = $atts['number'];
}
@ -202,7 +200,8 @@ class WC_Shortcodes {
}
$columns = absint( $atts['columns'] );
$woocommerce_loop['columns'] = $columns;
wc_set_loop_prop( 'columns', $columns );
ob_start();
@ -498,6 +497,11 @@ class WC_Shortcodes {
$args['p'] = absint( $atts['id'] );
}
// Don't render titles if desired.
if ( isset( $atts['show_title'] ) && ! $atts['show_title'] ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
$single_product = new WP_Query( $args );
$preselected_id = '0';
@ -565,6 +569,11 @@ class WC_Shortcodes {
// @codingStandardsIgnoreEnd
wp_reset_postdata();
// Re-enable titles if they were removed.
if ( isset( $atts['show_title'] ) && ! $atts['show_title'] ) {
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
return '<div class="woocommerce">' . ob_get_clean() . '</div>';
}

View File

@ -27,7 +27,7 @@ class WC_Tax {
*
* @var bool
*/
public static $round_at_subtotal;
public static $round_at_subtotal = false;
/**
* Load options.
@ -64,32 +64,20 @@ class WC_Tax {
/**
* Calculate tax for a line.
* @param float $price Price to calc tax on
* @param array $rates Rates to apply
* @param boolean $price_includes_tax Whether the passed price has taxes included
* @param boolean $suppress_rounding Whether to suppress any rounding from taking place
* @return array Array of rates + prices after tax
*
* @param float $price Price to calc tax on.
* @param array $rates Rates to apply.
* @param boolean $price_includes_tax Whether the passed price has taxes included.
* @param boolean $deprecated Whether to suppress any rounding from taking place. No longer used here.
* @return array Array of rates + prices after tax.
*/
public static function calc_tax( $price, $rates, $price_includes_tax = false, $suppress_rounding = false ) {
// Work in pence to X precision
$price = self::precision( $price );
public static function calc_tax( $price, $rates, $price_includes_tax = false, $deprecated = false ) {
if ( $price_includes_tax ) {
$taxes = self::calc_inclusive_tax( $price, $rates );
} else {
$taxes = self::calc_exclusive_tax( $price, $rates );
}
// Round to precision
if ( ! self::$round_at_subtotal && ! $suppress_rounding ) {
$taxes = array_map( 'round', $taxes ); // Round to precision
}
// Remove precision
$price = self::remove_precision( $price );
$taxes = array_map( array( __CLASS__, 'remove_precision' ), $taxes );
return apply_filters( 'woocommerce_calc_tax', $taxes, $price, $rates, $price_includes_tax, $suppress_rounding );
return apply_filters( 'woocommerce_calc_tax', $taxes, $price, $rates, $price_includes_tax, $deprecated );
}
/**
@ -104,24 +92,6 @@ class WC_Tax {
return apply_filters( 'woocommerce_calc_shipping_tax', $taxes, $price, $rates );
}
/**
* Multiply cost by pow precision.
* @param float $price
* @return float
*/
private static function precision( $price ) {
return $price * ( pow( 10, self::$precision ) );
}
/**
* Divide cost by pow precision.
* @param float $price
* @return float
*/
private static function remove_precision( $price ) {
return $price / ( pow( 10, self::$precision ) );
}
/**
* Round to precision.
*
@ -137,7 +107,7 @@ class WC_Tax {
* @return float
*/
public static function round( $in ) {
return apply_filters( 'woocommerce_tax_round', round( $in, self::$precision ), $in );
return apply_filters( 'woocommerce_tax_round', round( $in, wc_get_rounding_precision() ), $in );
}
/**

View File

@ -1,26 +1,50 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Template Loader
*
* @class WC_Template
* @version 2.2.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @author Automattic
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Template_Loader.
*/
class WC_Template_Loader {
/**
* Store the shop page ID.
*
* @var integer
*/
private static $shop_page_id = 0;
/**
* Store whether we're processing a product inside the_content filter.
*
* @var boolean
*/
private static $in_content_filter = false;
/**
* Hook in methods.
*/
public static function init() {
add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) );
self::$shop_page_id = wc_get_page_id( 'shop' );
// Supported themes.
if ( current_theme_supports( 'woocommerce' ) ) {
add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) );
} else {
// Unsupported themes.
add_action( 'template_redirect', array( __CLASS__, 'unsupported_theme_init' ) );
}
}
/**
@ -35,7 +59,7 @@ class WC_Template_Loader {
* this to the theme (containing a woocommerce() inside) this will be used for all.
* woocommerce templates.
*
* @param mixed $template
* @param string $template Template to load.
* @return string
*/
public static function template_loader( $template ) {
@ -71,15 +95,15 @@ class WC_Template_Loader {
if ( is_singular( 'product' ) ) {
$default_file = 'single-product.php';
} elseif ( is_product_taxonomy() ) {
$term = get_queried_object();
$object = get_queried_object();
if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
$default_file = 'taxonomy-' . $term->taxonomy . '.php';
$default_file = 'taxonomy-' . $object->taxonomy . '.php';
} else {
$default_file = 'archive-product.php';
}
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$default_file = 'archive-product.php';
$default_file = current_theme_supports( 'woocommerce' ) ? 'archive-product.php' : '';
} else {
$default_file = '';
}
@ -94,31 +118,40 @@ class WC_Template_Loader {
* @return string[]
*/
private static function get_template_loader_files( $default_file ) {
$search_files = apply_filters( 'woocommerce_template_loader_files', array(), $default_file );
$search_files[] = 'woocommerce.php';
$templates = apply_filters( 'woocommerce_template_loader_files', array(), $default_file );
$templates[] = 'woocommerce.php';
if ( is_page_template() ) {
$search_files[] = get_page_template_slug();
$templates[] = get_page_template_slug();
}
if ( is_singular( 'product' ) ) {
$object = get_queried_object();
$name_decoded = urldecode( $object->post_name );
if ( $name_decoded !== $object->post_name ) {
$templates[] = "single-product-{$name_decoded}.php";
}
$templates[] = "single-product-{$object->post_name}.php";
}
if ( is_product_taxonomy() ) {
$term = get_queried_object();
$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';
$object = get_queried_object();
$templates[] = 'taxonomy-' . $object->taxonomy . '-' . $object->slug . '.php';
$templates[] = WC()->template_path() . 'taxonomy-' . $object->taxonomy . '-' . $object->slug . '.php';
$templates[] = 'taxonomy-' . $object->taxonomy . '.php';
$templates[] = WC()->template_path() . 'taxonomy-' . $object->taxonomy . '.php';
}
$search_files[] = $default_file;
$search_files[] = WC()->template_path() . $default_file;
$templates[] = $default_file;
$templates[] = WC()->template_path() . $default_file;
return array_unique( $search_files );
return array_unique( $templates );
}
/**
* Load comments template.
*
* @param mixed $template
* @param string $template template to load.
* @return string
*/
public static function comments_template_loader( $template ) {
@ -144,6 +177,315 @@ class WC_Template_Loader {
}
}
}
/**
* Unsupported theme compatibility methods.
*/
/**
* Hook in methods to enhance the unsupported theme experience on pages.
*
* @since 3.3.0
*/
public static function unsupported_theme_init() {
if ( self::$shop_page_id ) {
if ( is_product_taxonomy() ) {
self::unsupported_theme_tax_archive_init();
} elseif ( is_product() ) {
self::unsupported_theme_product_page_init();
} else {
self::unsupported_theme_shop_page_init();
}
}
}
/**
* Hook in methods to enhance the unsupported theme experience on the Shop page.
*
* @since 3.3.0
*/
private static function unsupported_theme_shop_page_init() {
add_filter( 'the_content', array( __CLASS__, 'unsupported_theme_shop_content_filter' ), 10 );
add_filter( 'the_title', array( __CLASS__, 'unsupported_theme_title_filter' ), 10, 2 );
add_filter( 'comments_number', '__return_empty_string' );
}
/**
* Hook in methods to enhance the unsupported theme experience on Product pages.
*
* @since 3.3.0
*/
private static function unsupported_theme_product_page_init() {
add_filter( 'the_content', array( __CLASS__, 'unsupported_theme_product_content_filter' ), 10 );
add_filter( 'post_thumbnail_html', array( __CLASS__, 'unsupported_theme_single_featured_image_filter' ) );
add_filter( 'woocommerce_product_tabs', array( __CLASS__, 'unsupported_theme_remove_review_tab' ) );
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
/**
* Enhance the unsupported theme experience on Product Category and Attribute pages by rendering
* those pages using the single template and shortcode-based content. To do this we make a dummy
* post and set a shortcode as the post content. This approach is adapted from bbPress.
*
* @since 3.3.0
*/
private static function unsupported_theme_tax_archive_init() {
global $wp_query, $post;
$queried_object = get_queried_object();
$args = self::get_current_shop_view_args();
$shortcode_args = array(
'page' => $args->page,
'columns' => $args->columns,
'rows' => $args->rows,
'orderby' => '',
'order' => '',
'paginate' => true,
'cache' => false,
);
if ( is_product_category() ) {
$shortcode_args['category'] = sanitize_title( $queried_object->slug );
} elseif ( taxonomy_is_product_attribute( $queried_object->taxonomy ) ) {
$shortcode_args['attribute'] = sanitize_title( $queried_object->taxonomy );
$shortcode_args['terms'] = sanitize_title( $queried_object->slug );
} elseif ( is_product_tag() ) {
$shortcode_args['tag'] = sanitize_title( $queried_object->slug );
} else {
// Default theme archive for all other taxonomies.
return;
}
$shortcode = new WC_Shortcode_Products( $shortcode_args );
$shop_page = get_post( self::$shop_page_id );
$dummy_post_properties = array(
'ID' => 0,
'post_status' => 'publish',
'post_author' => $shop_page->post_author,
'post_parent' => 0,
'post_type' => 'page',
'post_date' => $shop_page->post_date,
'post_date_gmt' => $shop_page->post_date_gmt,
'post_modified' => $shop_page->post_modified,
'post_modified_gmt' => $shop_page->post_modified_gmt,
'post_content' => $shortcode->get_content(),
'post_title' => wc_clean( $queried_object->name ),
'post_excerpt' => '',
'post_content_filtered' => '',
'post_mime_type' => '',
'post_password' => '',
'post_name' => $queried_object->slug,
'guid' => '',
'menu_order' => 0,
'pinged' => '',
'to_ping' => '',
'ping_status' => '',
'comment_status' => 'closed',
'comment_count' => 0,
'filter' => 'raw',
);
// Set the $post global.
$post = new WP_Post( (object) $dummy_post_properties );
// Copy the new post global into the main $wp_query.
$wp_query->post = $post;
$wp_query->posts = array( $post );
// Prevent comments form from appearing.
$wp_query->post_count = 1;
$wp_query->is_404 = false;
$wp_query->is_page = true;
$wp_query->is_single = true;
$wp_query->is_archive = false;
$wp_query->is_tax = false;
// Prepare everything for rendering.
setup_postdata( $post );
remove_all_filters( 'the_content' );
remove_all_filters( 'the_excerpt' );
add_filter( 'template_include', array( __CLASS__, 'force_single_template_filter' ) );
}
/**
* Force the loading of one of the single templates instead of whatever template was about to be loaded.
*
* @since 3.3.0
* @param string $template Path to template.
* @return string
*/
public static function force_single_template_filter( $template ) {
$possible_templates = array(
'page',
'single',
'singular',
'index',
);
foreach ( $possible_templates as $possible_template ) {
$path = get_query_template( $possible_template );
if ( $path ) {
return $path;
}
}
return $template;
}
/**
* Get information about the current shop page view.
*
* @since 3.3.0
* @return array
*/
private static function get_current_shop_view_args() {
return (object) array(
'page' => absint( max( 1, absint( get_query_var( 'paged' ) ) ) ),
'columns' => wc_get_default_products_per_row(),
'rows' => wc_get_default_product_rows_per_page(),
);
}
/**
* Filter the title and insert WooCommerce content on the shop page.
*
* For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
*
* @since 3.3.0
* @param string $title Existing title.
* @param int $id ID of the post being filtered.
* @return string
*/
public static function unsupported_theme_title_filter( $title, $id ) {
if ( ! current_theme_supports( 'woocommerce' ) && is_page( self::$shop_page_id ) && $id === self::$shop_page_id ) {
$args = self::get_current_shop_view_args();
$title_suffix = array();
if ( $args->page > 1 ) {
$title_suffix[] = sprintf( esc_html__( 'Page %d', 'woocommerce' ), $args->page );
}
if ( $title_suffix ) {
$title = $title . ' &ndash; ' . implode( ', ', $title_suffix );
}
}
return $title;
}
/**
* Filter the content and insert WooCommerce content on the shop page.
*
* For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
*
* @since 3.3.0
* @param string $content Existing post content.
* @return string
*/
public static function unsupported_theme_shop_content_filter( $content ) {
global $wp_query;
if ( current_theme_supports( 'woocommerce' ) || ! is_main_query() ) {
return $content;
}
self::$in_content_filter = true;
// Remove the filter we're in to avoid nested calls.
remove_filter( 'the_content', array( __CLASS__, 'the_content_filter' ) );
// Unsupported theme shop page.
if ( is_page( self::$shop_page_id ) ) {
$args = self::get_current_shop_view_args();
$shortcode = new WC_Shortcode_Products(
array_merge(
wc()->query->get_catalog_ordering_args(),
array(
'page' => $args->page,
'columns' => $args->columns,
'rows' => $args->rows,
'orderby' => '',
'order' => '',
'paginate' => true,
'cache' => false,
)
),
'products' );
// Allow queries to run e.g. layered nav.
add_action( 'pre_get_posts', array( wc()->query, 'product_query' ) );
$content = $content . $shortcode->get_content();
// Remove actions and self to avoid nested calls.
remove_action( 'pre_get_posts', array( wc()->query, 'product_query' ) );
}
self::$in_content_filter = false;
return $content;
}
/**
* Filter the content and insert WooCommerce content on the shop page.
*
* For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
*
* @since 3.3.0
* @param string $content Existing post content.
* @return string
*/
public static function unsupported_theme_product_content_filter( $content ) {
global $wp_query;
if ( current_theme_supports( 'woocommerce' ) || ! is_main_query() ) {
return $content;
}
self::$in_content_filter = true;
// Remove the filter we're in to avoid nested calls.
remove_filter( 'the_content', array( __CLASS__, 'the_content_filter' ) );
if ( is_product() ) {
$content = do_shortcode( '[product_page id="' . get_the_ID() . '" show_title=0]' );
}
self::$in_content_filter = false;
return $content;
}
/**
* Prevent the main featured image on product pages because there will be another featured image
* in the gallery.
*
* @since 3.3.0
* @param string $html Img element HTML.
* @return string
*/
public static function unsupported_theme_single_featured_image_filter( $html ) {
if ( self::$in_content_filter || ! is_product() || ! is_main_query() ) {
return $html;
}
return '';
}
/**
* Remove the Review tab and just use the regular comment form.
*
* @param array $tabs Tab info.
* @return array
*/
public static function unsupported_theme_remove_review_tab( $tabs ) {
unset( $tabs['reviews'] );
return $tabs;
}
}
WC_Template_Loader::init();
add_action( 'init', array( 'WC_Template_Loader', 'init' ) );

View File

@ -338,6 +338,7 @@ final class WooCommerce {
include_once( WC_ABSPATH . 'includes/class-wc-background-emailer.php' );
include_once( WC_ABSPATH . 'includes/class-wc-discounts.php' );
include_once( WC_ABSPATH . 'includes/class-wc-cart-totals.php' );
include_once( WC_ABSPATH . 'includes/customizer/class-wc-customizer.php' );
include_once( WC_ABSPATH . 'includes/class-wc-regenerate-images.php' ); // Image regeneration class.
/**
@ -402,13 +403,11 @@ final class WooCommerce {
}
/**
* Include classes sfor theme support.
* Include classes for theme support.
*
* @since 3.3.0
*/
private function theme_support_includes() {
$theme_support = array( 'twentyseventeen', 'twentysixteen', 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' );
if ( $this->is_active_theme( array( 'twentyseventeen', 'twentysixteen', 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
switch ( get_template() ) {
case 'twentyten':

View File

@ -0,0 +1,65 @@
<?php
/**
* Custom control for radio buttons with nested options.
*
* Used for our image cropping settings.
*
* @version 3.3.0
* @package WooCommerce
* @author WooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Customizer_Control_Cropping class.
*/
class WC_Customizer_Control_Cropping extends WP_Customize_Control {
/**
* Declare the control type.
*
* @var string
*/
public $type = 'woocommerce-cropping-control';
/**
* Render control.
*/
public function render_content() {
if ( empty( $this->choices ) ) {
return;
}
$value = $this->value( 'cropping' );
$custom_width = $this->value( 'custom_width' );
$custom_height = $this->value( 'custom_height' );
?>
<span class="customize-control-title">
<?php echo esc_html( $this->label ); ?>
</span>
<?php if ( ! empty( $this->description ) ) : ?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php endif; ?>
<ul id="input_<?php echo esc_attr( $this->id ); ?>" class="woocommerce-cropping-control">
<?php foreach ( $this->choices as $key => $radio ) : ?>
<li>
<input type="radio" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $this->id . $key ); ?>" <?php $this->link( 'cropping' ); ?> <?php checked( $value, $key ); ?> />
<label for="<?php echo esc_attr( $this->id . $key ); ?>"><?php echo esc_html( $radio['label'] ); ?><br/><span class="description"><?php echo esc_html( $radio['description'] ); ?></span></label>
<?php if ( 'custom' === $key ) : ?>
<span class="woocommerce-cropping-control-aspect-ratio">
<input type="text" pattern="\d*" size="3" value="<?php echo esc_attr( $custom_width ); ?>" <?php $this->link( 'custom_width' ); ?> /> : <input type="text" pattern="\d*" size="3" value="<?php echo esc_attr( $custom_height ); ?>" <?php $this->link( 'custom_height' ); ?> />
</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php
}
}

View File

@ -0,0 +1,386 @@
<?php
/**
* Adds options to the customizer for WooCommerce.
*
* @version 3.3.0
* @package WooCommerce
* @author WooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Customizer class.
*/
class WC_Customizer {
/**
* Constructor.
*/
public function __construct() {
add_action( 'customize_register', array( $this, 'add_sections' ) );
add_action( 'customize_controls_print_styles', array( $this, 'add_styles' ) );
add_action( 'customize_controls_print_scripts', array( $this, 'add_scripts' ), 30 );
}
/**
* Add settings to the customizer.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
public function add_sections( $wp_customize ) {
$wp_customize->add_panel( 'woocommerce', array(
'priority' => 200,
'capability' => 'manage_woocommerce',
'theme_supports' => '',
'title' => __( 'WooCommerce', 'woocommerce' ),
) );
$this->add_store_notice_section( $wp_customize );
$this->add_product_grid_section( $wp_customize );
$this->add_product_images_section( $wp_customize );
}
/**
* CSS styles to improve our form.
*/
public function add_styles() {
?>
<style type="text/css">
.woocommerce-cropping-control {
margin: 0 40px 1em 0;
padding: 0;
display:inline-block;
vertical-align: top;
}
.woocommerce-cropping-control input[type=radio] {
margin-top: 1px;
}
.woocommerce-cropping-control span.woocommerce-cropping-control-aspect-ratio {
margin-top: .5em;
display:block;
}
.woocommerce-cropping-control span.woocommerce-cropping-control-aspect-ratio input {
width: auto;
display: inline-block;
}
</style>
<?php
}
/**
* Scripts to improve our form.
*/
public function add_scripts() {
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( document.body ).on( 'change', '.woocommerce-cropping-control input[type="radio"]', function() {
var $wrapper = $( this ).closest( '.woocommerce-cropping-control' ),
value = $wrapper.find( 'input:checked' ).val();
if ( 'custom' === value ) {
$wrapper.find( '.woocommerce-cropping-control-aspect-ratio' ).slideDown( 200 );
} else {
$wrapper.find( '.woocommerce-cropping-control-aspect-ratio' ).hide();
}
return false;
} );
wp.customize.bind( 'ready', function() { // Ready?
$( '.woocommerce-cropping-control' ).find( 'input:checked' ).change();
} );
} );
</script>
<?php
}
/**
* Should our settings show?
*
* @return boolean
*/
public function is_active() {
return is_woocommerce() || wc_post_content_has_shortcode( 'products' ) || ! current_theme_supports( 'woocommerce' );
}
/**
* Store notice section.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
private function add_store_notice_section( $wp_customize ) {
$wp_customize->add_section(
'woocommerce_store_notice',
array(
'title' => __( 'Store Notice', 'woocommerce' ),
'priority' => 10,
'panel' => 'woocommerce',
)
);
$wp_customize->add_setting(
'woocommerce_demo_store',
array(
'default' => 'no',
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'wc_bool_to_string',
'sanitize_js_callback' => 'wc_string_to_bool',
)
);
$wp_customize->add_setting(
'woocommerce_demo_store_notice',
array(
'default' => __( 'This is a demo store for testing purposes &mdash; no orders shall be fulfilled.', 'woocommerce' ),
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'wp_kses_post',
)
);
$wp_customize->add_control(
'woocommerce_demo_store_notice',
array(
'label' => __( 'Store notice', 'woocommerce' ),
'description' => __( 'If enabled, this text will be shown site-wide. You can use it to show events or promotions to visitors!', 'woocommerce' ),
'section' => 'woocommerce_store_notice',
'settings' => 'woocommerce_demo_store_notice',
'type' => 'textarea',
)
);
$wp_customize->add_control(
'woocommerce_demo_store',
array(
'label' => __( 'Enable store notice', 'woocommerce' ),
'section' => 'woocommerce_store_notice',
'settings' => 'woocommerce_demo_store',
'type' => 'checkbox',
)
);
}
/**
* Product grid section.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
public function add_product_grid_section( $wp_customize ) {
if ( has_filter( 'loop_shop_columns' ) ) {
return;
}
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
$wp_customize->add_section(
'woocommerce_product_grid',
array(
'title' => __( 'Product Grid', 'woocommerce' ),
'priority' => 10,
'active_callback' => array( $this, 'is_active' ),
'panel' => 'woocommerce',
)
);
$wp_customize->add_setting(
'woocommerce_catalog_columns',
array(
'default' => 3,
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_control(
'woocommerce_catalog_columns',
array(
'label' => __( 'Products per row', 'woocommerce' ),
'description' => __( 'How many products should be shown per row?', 'woocommerce' ),
'section' => 'woocommerce_product_grid',
'settings' => 'woocommerce_catalog_columns',
'type' => 'number',
'input_attrs' => array(
'min' => isset( $theme_support['product_grid']['min_columns'] ) ? absint( $theme_support['product_grid']['min_columns'] ) : 1,
'max' => isset( $theme_support['product_grid']['max_columns'] ) ? absint( $theme_support['product_grid']['max_columns'] ) : '',
'step' => 1,
),
)
);
$wp_customize->add_setting(
'woocommerce_catalog_rows',
array(
'default' => 4,
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_control(
'woocommerce_catalog_rows',
array(
'label' => __( 'Rows per page', 'woocommerce' ),
'description' => __( 'How many rows of products should be shown per page?', 'woocommerce' ),
'section' => 'woocommerce_product_grid',
'settings' => 'woocommerce_catalog_rows',
'type' => 'number',
'input_attrs' => array(
'min' => isset( $theme_support['product_grid']['min_rows'] ) ? absint( $theme_support['product_grid']['min_rows'] ): 1,
'max' => isset( $theme_support['product_grid']['max_rows'] ) ? absint( $theme_support['product_grid']['max_rows'] ): '',
'step' => 1,
),
)
);
}
/**
* Product images section.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
private function add_product_images_section( $wp_customize ) {
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0]: false;
$wp_customize->add_section(
'woocommerce_product_images',
array(
'title' => __( 'Product Images', 'woocommerce' ),
'priority' => 20,
'active_callback' => array( $this, 'is_active' ),
'panel' => 'woocommerce',
)
);
if ( ! isset( $theme_support['single_image_width'] ) ) {
$wp_customize->add_setting(
'single_image_width',
array(
'default' => 600,
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_control(
'single_image_width',
array(
'label' => __( 'Main image width', 'woocommerce' ),
'description' => __( 'This is the width used by the main image on single product pages. These images will remain uncropped.', 'woocommerce' ),
'section' => 'woocommerce_product_images',
'settings' => 'single_image_width',
'type' => 'number',
'input_attrs' => array(
'min' => 0,
'step' => 1,
),
)
);
}
if ( ! isset( $theme_support['thumbnail_image_width'] ) ) {
$wp_customize->add_setting(
'thumbnail_image_width',
array(
'default' => 300,
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_control(
'thumbnail_image_width',
array(
'label' => __( 'Thumbnail width', 'woocommerce' ),
'description' => __( 'This size is used for product archives and product listings.', 'woocommerce' ),
'section' => 'woocommerce_product_images',
'settings' => 'thumbnail_image_width',
'type' => 'number',
'input_attrs' => array( 'min' => 0, 'step' => 1 ),
)
);
}
include_once( WC_ABSPATH . 'includes/customizer/class-wc-customizer-control-cropping.php' );
$wp_customize->add_setting(
'woocommerce_thumbnail_cropping',
array(
'default' => '1:1',
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'wc_clean',
)
);
$wp_customize->add_setting(
'woocommerce_thumbnail_cropping_custom_width',
array(
'default' => '4',
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_setting(
'woocommerce_thumbnail_cropping_custom_height',
array(
'default' => '3',
'type' => 'option',
'capability' => 'manage_woocommerce',
'sanitize_callback' => 'absint',
'sanitize_js_callback' => 'absint',
)
);
$wp_customize->add_control(
new WC_Customizer_Control_Cropping(
$wp_customize,
'woocommerce_thumbnail_cropping',
array(
'section' => 'woocommerce_product_images',
'settings' => array(
'cropping' => 'woocommerce_thumbnail_cropping',
'custom_width' => 'woocommerce_thumbnail_cropping_custom_width',
'custom_height' => 'woocommerce_thumbnail_cropping_custom_height',
),
'label' => __( 'Thumbnail cropping', 'woocommerce' ),
'choices' => array(
'1:1' => array(
'label' => __( '1:1', 'woocommerce' ),
'description' => __( 'Images will be cropped into a square', 'woocommerce' ),
),
'custom' => array(
'label' => __( 'Custom', 'woocommerce' ),
'description' => __( 'Images will be cropped to a custom aspect ratio', 'woocommerce' ),
),
'uncropped' => array(
'label' => __( 'Uncropped', 'woocommerce' ),
'description' => __( 'Images will display using the aspect ratio in which they were uploaded', 'woocommerce' ),
),
),
)
)
);
}
}
new WC_Customizer();

View File

@ -234,10 +234,10 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*
* @since 3.0.0
* @param WC_Product $product Product object.
* @param bool $include_taxes If taxes should be calculated or not.
* @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
* @return array of prices
*/
public function read_price_data( &$product, $include_taxes = false ) {
public function read_price_data( &$product, $for_display = false ) {
/**
* Transient name for storing prices for this product (note: Max transient length is 45)
@ -246,7 +246,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
$transient_name = 'wc_var_prices_' . $product->get_id();
$price_hash = $this->get_price_hash( $product, $include_taxes );
$price_hash = $this->get_price_hash( $product, $for_display );
/**
* $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.
@ -283,7 +283,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
}
// If we are getting prices for display, we need to account for taxes.
if ( $include_taxes ) {
if ( $for_display ) {
if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
$price = '' === $price ? '' : wc_get_price_including_tax( $variation, array( 'qty' => 1, 'price' => $price ) );
$regular_price = '' === $regular_price ? '' : wc_get_price_including_tax( $variation, array( 'qty' => 1, 'price' => $regular_price ) );
@ -307,14 +307,14 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
'sale_price' => $sale_prices,
);
set_transient( $transient_name, json_encode( $transient_cached_prices_array ), DAY_IN_SECONDS * 30 );
set_transient( $transient_name, wp_json_encode( $transient_cached_prices_array ), DAY_IN_SECONDS * 30 );
}
/**
* Give plugins one last chance to filter the variation prices array which has been generated and store locally to the class.
* This value may differ from the transient cache. It is filtered once before storing locally.
*/
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $transient_cached_prices_array[ $price_hash ], $product, $include_taxes );
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $transient_cached_prices_array[ $price_hash ], $product, $for_display );
}
return $this->prices_array[ $price_hash ];
}
@ -325,13 +325,13 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*
* @since 3.0.0
* @param WC_Product $product Product object.
* @param bool $include_taxes If taxes should be calculated or not.
* @param bool $for_display If taxes should be calculated or not.
* @return string
*/
protected function get_price_hash( &$product, $include_taxes = false ) {
protected function get_price_hash( &$product, $for_display = false ) {
global $wp_filter;
$price_hash = $include_taxes ? array( get_option( 'woocommerce_tax_display_shop', 'excl' ), WC_Tax::get_rates() ) : array( false );
$price_hash = $for_display ? 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 ) {
@ -345,7 +345,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
}
$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 = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $for_display ) ) );
return $price_hash;
}

View File

@ -7,6 +7,7 @@
* @package WooCommerce/Export
* @version 3.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -18,42 +19,49 @@ abstract class WC_CSV_Exporter {
/**
* Type of export used in filter names.
*
* @var string
*/
protected $export_type = '';
/**
* Batch limit.
*
* @var integer
*/
protected $limit = 50;
/**
* Number exported.
*
* @var integer
*/
protected $exported_row_count = 0;
/**
* Raw data to export.
*
* @var array
*/
protected $row_data = array();
/**
* Total rows to export.
*
* @var integer
*/
protected $total_rows = 0;
/**
* Columns ids and names.
*
* @var array
*/
protected $column_names = array();
/**
* List of columns to export, or empty for all.
*
* @var array
*/
protected $columns_to_export = array();
@ -77,7 +85,7 @@ abstract class WC_CSV_Exporter {
* Set column names.
*
* @since 3.1.0
* @param array $column_names
* @param array $column_names Column names array.
*/
public function set_column_names( $column_names ) {
$this->column_names = array();
@ -101,7 +109,7 @@ abstract class WC_CSV_Exporter {
* Set columns to export.
*
* @since 3.1.0
* @param array $column_names
* @param array $columns Columns array.
*/
public function set_columns_to_export( $columns ) {
$this->columns_to_export = array_map( 'wc_clean', $columns );
@ -111,7 +119,7 @@ abstract class WC_CSV_Exporter {
* See if a column is to be exported or not.
*
* @since 3.1.0
* @param string $column_id
* @param string $column_id ID of the column being exported.
* @return boolean
*/
public function is_column_exporting( $column_id ) {
@ -122,7 +130,7 @@ abstract class WC_CSV_Exporter {
return true;
}
if ( in_array( $column_id, $columns_to_export ) || 'meta' === $column_id ) {
if ( in_array( $column_id, $columns_to_export, true ) || 'meta' === $column_id ) {
return true;
}
@ -161,11 +169,11 @@ abstract class WC_CSV_Exporter {
gc_enable();
}
if ( function_exists( 'apache_setenv' ) ) {
@apache_setenv( 'no-gzip', 1 );
@apache_setenv( 'no-gzip', 1 ); // @codingStandardsIgnoreLine
}
@ini_set( 'zlib.output_compression', 'Off' );
@ini_set( 'output_buffering', 'Off' );
@ini_set( 'output_handler', '' );
@ini_set( 'zlib.output_compression', 'Off' ); // @codingStandardsIgnoreLine
@ini_set( 'output_buffering', 'Off' ); // @codingStandardsIgnoreLine
@ini_set( 'output_handler', '' ); // @codingStandardsIgnoreLine
ignore_user_abort( true );
wc_set_time_limit( 0 );
wc_nocache_headers();
@ -188,9 +196,10 @@ abstract class WC_CSV_Exporter {
* Set the export content.
*
* @since 3.1.0
* @param string $csv_data All CSV content.
*/
public function send_content( $csv_data ) {
echo $csv_data;
echo $csv_data; // @codingStandardsIgnoreLine
}
/**
@ -219,10 +228,10 @@ abstract class WC_CSV_Exporter {
if ( ! $this->is_column_exporting( $column_id ) ) {
continue;
}
$export_row[] = $column_name;
$export_row[] = $this->format_data( $column_name );
}
fputcsv( $buffer, $export_row );
fputcsv( $buffer, $export_row ); // @codingStandardsIgnoreLine
return ob_get_clean();
}
@ -257,7 +266,9 @@ abstract class WC_CSV_Exporter {
* Export rows to an array ready for the CSV.
*
* @since 3.1.0
* @param array $row_data
* @param array $row_data Data to export.
* @param string $key Column being exported.
* @param resource $buffer Output buffer.
*/
protected function export_row( $row_data, $key, $buffer ) {
$columns = $this->get_column_names();
@ -274,7 +285,7 @@ abstract class WC_CSV_Exporter {
}
}
fputcsv( $buffer, $export_row );
fputcsv( $buffer, $export_row ); // @codingStandardsIgnoreLine
++ $this->exported_row_count;
}
@ -292,7 +303,7 @@ abstract class WC_CSV_Exporter {
* Set batch limit.
*
* @since 3.1.0
* @param int $limit
* @param int $limit Limit to export.
*/
public function set_limit( $limit ) {
$this->limit = absint( $limit );
@ -321,7 +332,7 @@ abstract class WC_CSV_Exporter {
* @see https://hackerone.com/reports/72785
*
* @since 3.1.0
* @param string $field CSV field to escape
* @param string $data CSV field to escape.
* @return string
*/
public function escape_data( $data ) {
@ -338,7 +349,7 @@ abstract class WC_CSV_Exporter {
* Format and escape data ready for the CSV file.
*
* @since 3.1.0
* @param string $data
* @param string $data Data to format.
* @return string
*/
public function format_data( $data ) {
@ -362,8 +373,8 @@ abstract class WC_CSV_Exporter {
* Format term ids to names.
*
* @since 3.1.0
* @param array $term_ids
* @param string $taxonomy
* @param array $term_ids Term IDs to format.
* @param string $taxonomy Taxonomy name.
* @return array
*/
public function format_term_ids( $term_ids, $taxonomy ) {
@ -413,7 +424,7 @@ abstract class WC_CSV_Exporter {
* which contain the separator.
*
* @since 3.2.0
* @param array $values
* @param array $values Values to implode.
* @return string
*/
protected function implode_values( $values ) {

View File

@ -7,6 +7,7 @@
* @package WooCommerce/Export
* @version 3.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -25,18 +26,21 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
/**
* Type of export used in filter names.
*
* @var string
*/
protected $export_type = 'product';
/**
* Should meta be exported?
*
* @var boolean
*/
protected $enable_meta_export = false;
/**
* Which product types are being exported.
*
* @var array
*/
protected $product_types_to_export = array();
@ -53,7 +57,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Should meta be exported?
*
* @since 3.1.0
* @param bool $enable_meta_export
* @param bool $enable_meta_export Should meta be exported.
*/
public function enable_meta_export( $enable_meta_export ) {
$this->enable_meta_export = (bool) $enable_meta_export;
@ -63,7 +67,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Product types to export.
*
* @since 3.1.0
* @param array $product_types_to_export
* @param array $product_types_to_export List of types to export.
*/
public function set_product_types_to_export( $product_types_to_export ) {
$this->product_types_to_export = array_map( 'wc_clean', $product_types_to_export );
@ -126,7 +130,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
public function prepare_data_to_export() {
$columns = $this->get_column_names();
$args = apply_filters( "woocommerce_product_export_{$this->export_type}_query_args", array(
'status' => array( 'private', 'publish' ),
'status' => array( 'private', 'publish', 'draft' ),
'type' => $this->product_types_to_export,
'limit' => $this->get_limit(),
'page' => $this->get_page(),
@ -148,20 +152,20 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
$value = '';
// Skip some columns if dynamically handled later or if we're being selective.
if ( in_array( $column_id, array( 'downloads', 'attributes', 'meta' ) ) || ! $this->is_column_exporting( $column_id ) ) {
if ( in_array( $column_id, array( 'downloads', 'attributes', 'meta' ), true ) || ! $this->is_column_exporting( $column_id ) ) {
continue;
}
// Filter for 3rd parties.
if ( has_filter( "woocommerce_product_export_{$this->export_type}_column_{$column_id}" ) ) {
// Filter for 3rd parties.
$value = apply_filters( "woocommerce_product_export_{$this->export_type}_column_{$column_id}", '', $product, $column_id );
// Handle special columns which don't map 1:1 to product data.
} elseif ( is_callable( array( $this, "get_column_value_{$column_id}" ) ) ) {
// Handle special columns which don't map 1:1 to product data.
$value = $this->{"get_column_value_{$column_id}"}( $product );
// Default and custom handling.
} elseif ( is_callable( array( $product, "get_{$column_id}" ) ) ) {
// Default and custom handling.
$value = $product->{"get_{$column_id}"}( 'edit' );
}
@ -180,18 +184,26 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get published value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return int
*/
protected function get_column_value_published( $product ) {
return 'publish' === $product->get_status( 'edit' ) ? 1 : 0;
$statuses = array(
'draft' => -1,
'private' => 0,
'publish' => 1,
);
$status = $product->get_status( 'edit' );
return isset( $statuses[ $status ] ) ? $statuses[ $status ] : -1;
}
/**
* Get product_cat value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_category_ids( $product ) {
@ -203,7 +215,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get product_tag value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_tag_ids( $product ) {
@ -215,7 +227,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get product_shipping_class value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_shipping_class_id( $product ) {
@ -227,7 +239,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get images value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_images( $product ) {
@ -249,7 +261,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Prepare linked products for export.
*
* @since 3.1.0
* @param int[] $linked_products
* @param int[] $linked_products Array of linked product ids.
* @return string
*/
protected function prepare_linked_products_for_export( $linked_products ) {
@ -270,7 +282,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get cross_sell_ids value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_cross_sell_ids( $product ) {
@ -281,7 +293,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get upsell_ids value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_upsell_ids( $product ) {
@ -292,7 +304,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get parent_id value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_parent_id( $product ) {
@ -311,7 +323,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get grouped_products value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_grouped_products( $product ) {
@ -336,7 +348,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get download_limit value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_download_limit( $product ) {
@ -347,7 +359,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get download_expiry value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_download_expiry( $product ) {
@ -358,7 +370,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get stock value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_stock( $product ) {
@ -378,7 +390,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get stock status value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_stock_status( $product ) {
@ -395,7 +407,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get backorders.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_backorders( $product ) {
@ -413,7 +425,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Get type value.
*
* @since 3.1.0
* @param WC_Product $product
* @param WC_Product $product Product being exported.
* @return string
*/
protected function get_column_value_type( $product ) {
@ -435,8 +447,8 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Export downloads.
*
* @since 3.1.0
* @param WC_Product $product
* @param array $row
* @param WC_Product $product Product being exported.
* @param array $row Row being exported.
*/
protected function prepare_downloads_for_export( $product, &$row ) {
if ( $product->is_downloadable() && $this->is_column_exporting( 'downloads' ) ) {
@ -459,8 +471,8 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
* Export attributes data.
*
* @since 3.1.0
* @param WC_Product $product
* @param array $row
* @param WC_Product $product Product being exported.
* @param array $row Row being exported.
*/
protected function prepare_attributes_for_export( $product, &$row ) {
if ( $this->is_column_exporting( 'attributes' ) ) {
@ -498,7 +510,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
$row[ 'attributes:name' . $i ] = wc_attribute_label( $attribute_name, $product );
if ( 0 === strpos( $attribute_name, 'pa_' ) ) {
$option_term = get_term_by( 'slug', $attribute, $attribute_name );
$option_term = get_term_by( 'slug', $attribute, $attribute_name ); // @codingStandardsIgnoreLine.
$row[ 'attributes:value' . $i ] = $option_term && ! is_wp_error( $option_term ) ? str_replace( ',', '\\,', $option_term->name ) : $attribute;
$row[ 'attributes:taxonomy' . $i ] = 1;
} else {
@ -514,7 +526,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
$default_value = $default_attributes[ sanitize_title( $attribute_name ) ];
if ( 0 === strpos( $attribute_name, 'pa_' ) ) {
$option_term = get_term_by( 'slug', $default_value, $attribute_name );
$option_term = get_term_by( 'slug', $default_value, $attribute_name ); // @codingStandardsIgnoreLine.
$row[ 'attributes:default' . $i ] = $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $default_value;
} else {
$row[ 'attributes:default' . $i ] = $default_value;

View File

@ -418,8 +418,12 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
$parent_attributes = $this->get_variation_parent_attributes( $data['raw_attributes'], $parent );
foreach ( $data['raw_attributes'] as $attribute ) {
$attribute_id = 0;
// Get ID if is a global attribute.
$attribute_id = wc_attribute_taxonomy_id_by_name( $attribute['name'] );
if ( ! empty( $attribute['taxonomy'] ) ) {
$attribute_id = $this->get_attribute_taxonomy_id( $attribute['name'] );
}
if ( $attribute_id ) {
$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
@ -587,7 +591,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
* Get attribute taxonomy ID from the imported data.
* If does not exists register a new attribute.
*
* @param string $name Attribute name.
* @param string $raw_name Attribute name.
* @return int
*/
public function get_attribute_taxonomy_id( $raw_name ) {

View File

@ -136,14 +136,26 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
return '';
}
// IDs are prefixed with id:.
if ( preg_match( '/^id:(\d+)$/', $value, $matches ) ) {
$id = intval( $matches[1] );
$id = intval( $matches[1] );
// If original_id is found, use that instead of the given ID since a new placeholder must have been created already.
$original_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_original_id' AND meta_value = %s;", $id ) );
if ( $original_id ) {
return absint( $original_id );
} elseif ( ! $this->params['update_existing'] ) {
// If we're not updating existing posts, we need a placeholder.
}
// See if the given ID maps to a valid product allready.
$existing_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type IN ( 'product', 'product_variation' ) AND ID = %d;", $id ) );
if ( $existing_id ) {
return absint( $existing_id );
}
// If we're not updating existing posts, we may need a placeholder product to map to.
if ( ! $this->params['update_existing'] ) {
$product = new WC_Product_Simple();
$product->set_name( 'Import placeholder for ' . $id );
$product->set_status( 'importing' );
@ -517,7 +529,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$data_formatting = array(
'id' => array( $this, 'parse_id_field' ),
'type' => array( $this, 'parse_comma_field' ),
'published' => array( $this, 'parse_bool_field' ),
'published' => array( $this, 'parse_float_field' ),
'featured' => array( $this, 'parse_bool_field' ),
'date_on_sale_from' => array( $this, 'parse_date_field' ),
'date_on_sale_to' => array( $this, 'parse_date_field' ),
@ -628,8 +640,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
// Status is mapped from a special published field.
if ( isset( $data['published'] ) ) {
$non_published_status = isset( $data['type'] ) && 'variation' === $data['type'] ? 'private' : 'draft';
$data['status'] = ( $data['published'] ? 'publish' : $non_published_status );
$statuses = array(
-1 => 'draft',
0 => 'private',
1 => 'publish',
);
$data['status'] = isset( $statuses[ $data['published'] ] ) ? $statuses[ $data['published'] ] : -1;
unset( $data['published'] );
}

View File

@ -114,7 +114,8 @@ class WC_Shortcode_Products {
return shortcode_atts( array(
'limit' => '-1', // Results limit.
'columns' => '4', // Number of columns.
'columns' => '3', // Number of columns.
'rows' => '', // Number of rows. If defined, limit will be ignored.
'orderby' => 'title', // menu_order, title, date, rand, price, popularity, rating, or id.
'order' => 'ASC', // ASC or DESC.
'ids' => '', // Comma separated IDs.
@ -124,8 +125,12 @@ class WC_Shortcode_Products {
'attribute' => '', // Single attribute slug.
'terms' => '', // Comma separated term slugs.
'terms_operator' => 'IN', // Operator to compare terms. Possible values are 'IN', 'NOT IN', 'AND'.
'tag' => '', // Comma separated tag slugs.
'visibility' => 'visible', // Possible values are 'visible', 'catalog', 'search', 'hidden'.
'class' => '', // HTML class.
'page' => 1, // Page for pagination.
'paginate' => false, // Should results be paginated.
'cache' => true, // Should shortcode output be cached.
), $attributes, $this->type );
}
@ -164,13 +169,30 @@ class WC_Shortcode_Products {
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'no_found_rows' => false === wc_string_to_bool( $this->attributes['paginate'] ),
'orderby' => $this->attributes['orderby'],
'order' => strtoupper( $this->attributes['order'] ),
);
if ( wc_string_to_bool( $this->attributes['paginate'] ) ) {
$this->attributes['page'] = get_query_var( 'product-page', 1 );
}
if ( ! empty( $this->attributes['rows'] ) ) {
$this->attributes['limit'] = $this->attributes['columns'] * $this->attributes['rows'];
}
// @codingStandardsIgnoreStart
$query_args['posts_per_page'] = (int) $this->attributes['limit'];
$ordering_args = WC()->query->get_catalog_ordering_args( $query_args['orderby'], $query_args['order'] );
$query_args['orderby'] = $ordering_args['orderby'];
$query_args['order'] = $ordering_args['order'];
if ( $ordering_args['meta_key'] ) {
$query_args['meta_key'] = $ordering_args['meta_key'];
}
$query_args['posts_per_page'] = intval( $this->attributes['limit'] );
if ( 1 < $this->attributes['page'] ) {
$query_args['paged'] = absint( $this->attributes['page'] );
}
$query_args['meta_query'] = WC()->query->get_meta_query();
$query_args['tax_query'] = array();
// @codingStandardsIgnoreEnd
@ -195,6 +217,9 @@ class WC_Shortcode_Products {
// Categories.
$this->set_categories_query_args( $query_args );
// Tags.
$this->set_tags_query_args( $query_args );
$query_args = apply_filters( 'woocommerce_shortcode_products_query', $query_args, $this->attributes, $this->type );
// Always query only IDs.
@ -263,11 +288,6 @@ class WC_Shortcode_Products {
*/
protected function set_categories_query_args( &$query_args ) {
if ( ! empty( $this->attributes['category'] ) ) {
$ordering_args = WC()->query->get_catalog_ordering_args( $query_args['orderby'], $query_args['order'] );
$query_args['orderby'] = $ordering_args['orderby'];
$query_args['order'] = $ordering_args['order'];
$query_args['meta_key'] = $ordering_args['meta_key']; // @codingStandardsIgnoreLine
$query_args['tax_query'][] = array(
'taxonomy' => 'product_cat',
'terms' => array_map( 'sanitize_title', explode( ',', $this->attributes['category'] ) ),
@ -277,6 +297,23 @@ class WC_Shortcode_Products {
}
}
/**
* Set tags query args.
*
* @since 3.3.0
* @param array $query_args Query args.
*/
protected function set_tags_query_args( &$query_args ) {
if ( ! empty( $this->attributes['tag'] ) ) {
$query_args['tax_query'][] = array(
'taxonomy' => 'product_tag',
'terms' => array_map( 'sanitize_title', explode( ',', $this->attributes['tag'] ) ),
'field' => 'slug',
'operator' => 'IN',
);
}
}
/**
* Set sale products query args.
*
@ -451,35 +488,44 @@ class WC_Shortcode_Products {
}
/**
* Get products IDs.
* Run the query and return an array of data, including queried ids and pagination information.
*
* @since 3.2.4
* @return array
* @since 3.3.0
* @return object Object with the following props; ids, per_page, found_posts, max_num_pages, current_page
*/
protected function get_products_ids() {
protected function get_query_results() {
$transient_name = $this->get_transient_name();
$ids = get_transient( $transient_name );
$cache = wc_string_to_bool( $this->attributes['cache'] ) === true;
$results = $cache ? get_transient( $transient_name ) : false;
if ( false === $ids ) {
if ( false === $results ) {
if ( 'top_rated_products' === $this->type ) {
add_filter( 'posts_clauses', array( __CLASS__, 'order_by_rating_post_clauses' ) );
$products = new WP_Query( $this->query_args );
$query = new WP_Query( $this->query_args );
remove_filter( 'posts_clauses', array( __CLASS__, 'order_by_rating_post_clauses' ) );
} else {
$products = new WP_Query( $this->query_args );
$query = new WP_Query( $this->query_args );
}
$ids = wp_parse_id_list( $products->posts );
$paginated = ! $query->get( 'no_found_rows' );
set_transient( $transient_name, $ids, DAY_IN_SECONDS * 30 );
$results = (object) array(
'ids' => wp_parse_id_list( $query->posts ),
'total' => $paginated ? (int) $query->found_posts : count( $query->posts ),
'total_pages' => $paginated ? (int) $query->max_num_pages : 1,
'per_page' => (int) $query->get( 'posts_per_page' ),
'current_page' => $paginated ? (int) max( 1, $query->get( 'paged', 1 ) ) : 1,
);
if ( $cache ) {
set_transient( $transient_name, $results, DAY_IN_SECONDS * 30 );
}
}
// Remove ordering query arguments.
if ( ! empty( $this->attributes['category'] ) ) {
WC()->query->remove_ordering_args();
}
return $ids;
return $results;
}
/**
@ -489,53 +535,65 @@ class WC_Shortcode_Products {
* @return string
*/
protected function product_loop() {
global $woocommerce_loop;
$columns = absint( $this->attributes['columns'] );
$classes = $this->get_wrapper_classes( $columns );
$woocommerce_loop['columns'] = $columns;
$woocommerce_loop['name'] = $this->type;
$products_ids = $this->get_products_ids();
$columns = absint( $this->attributes['columns'] );
$classes = $this->get_wrapper_classes( $columns );
$products = $this->get_query_results();
ob_start();
if ( $products_ids ) {
if ( $products && $products->ids ) {
// Prime meta cache to reduce future queries.
update_meta_cache( 'post', $products_ids );
update_object_term_cache( $products_ids, 'product' );
update_meta_cache( 'post', $products->ids );
update_object_term_cache( $products->ids, 'product' );
// Setup the loop.
wc_setup_loop( array(
'columns' => $columns,
'name' => $this->type,
'is_shortcode' => true,
'is_search' => false,
'is_paginated' => wc_string_to_bool( $this->attributes['paginate'] ),
'total' => $products->total,
'total_pages' => $products->total_pages,
'per_page' => $products->per_page,
'current_page' => $products->current_page,
) );
$original_post = $GLOBALS['post'];
do_action( "woocommerce_shortcode_before_{$this->type}_loop", $this->attributes );
do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
foreach ( $products_ids as $product_id ) {
$GLOBALS['post'] = get_post( $product_id ); // WPCS: override ok.
setup_postdata( $GLOBALS['post'] );
if ( wc_get_loop_prop( 'total' ) ) {
foreach ( $products->ids as $product_id ) {
$GLOBALS['post'] = get_post( $product_id ); // WPCS: override ok.
setup_postdata( $GLOBALS['post'] );
// Set custom product visibility when quering hidden products.
add_action( 'woocommerce_product_is_visible', array( $this, 'set_product_as_visible' ) );
// Set custom product visibility when quering hidden products.
add_action( 'woocommerce_product_is_visible', array( $this, 'set_product_as_visible' ) );
// Render product template.
wc_get_template_part( 'content', 'product' );
// Render product template.
wc_get_template_part( 'content', 'product' );
// Restore product visibility.
remove_action( 'woocommerce_product_is_visible', array( $this, 'set_product_as_visible' ) );
// Restore product visibility.
remove_action( 'woocommerce_product_is_visible', array( $this, 'set_product_as_visible' ) );
}
}
$GLOBALS['post'] = $original_post; // WPCS: override ok.
woocommerce_product_loop_end();
do_action( 'woocommerce_after_shop_loop' );
do_action( "woocommerce_shortcode_after_{$this->type}_loop", $this->attributes );
wp_reset_postdata();
wc_reset_loop();
} else {
do_action( "woocommerce_shortcode_{$this->type}_loop_no_results", $this->attributes );
}
woocommerce_reset_loop();
return '<div class="' . esc_attr( implode( ' ', $classes ) ) . '">' . ob_get_clean() . '</div>';
}

View File

@ -17,13 +17,17 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* Returns the url to the lost password endpoint url.
*
* @access public
* @param string $default_url
* @param string $default_url Default lost password URL.
* @return string
*/
function wc_lostpassword_url( $default_url = '' ) {
// Avoid loading too early.
if ( ! did_action( 'init' ) ) {
return $default_url;
}
// Don't redirect to the woocommerce endpoint on global network admin lost passwords.
if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( $_GET['redirect_to'], network_admin_url() ) ) {
if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) { // WPCS: input var ok, sanitization ok.
return $default_url;
}

View File

@ -362,32 +362,23 @@ function wc_cart_totals_shipping_method_label( $method ) {
/**
* Round discount.
*
* @param float $value
* @param int $precision
* @param double $value Amount to round.
* @param int $precision DP to round.
* @return float
*/
function wc_cart_round_discount( $value, $precision ) {
if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE );
} elseif ( 2 === WC_DISCOUNT_ROUNDING_MODE ) {
return wc_legacy_round_half_down( $value, $precision );
} else {
// Fake it in PHP 5.2.
if ( 2 === WC_DISCOUNT_ROUNDING_MODE && strstr( $value, '.' ) ) {
$value = (string) $value;
$value = explode( '.', $value );
$value[1] = substr( $value[1], 0, $precision + 1 );
$value = implode( '.', $value );
if ( substr( $value, -1 ) === '5' ) {
$value = substr( $value, 0, -1 ) . '4';
}
$value = floatval( $value );
}
return round( $value, $precision );
return round( $value, $precision );
}
}
/**
* Gets chosen shipping method IDs from chosen_shipping_methods session, without instance IDs.
*
* @since 2.6.2
* @return string[]
*/

View File

@ -260,7 +260,7 @@ if ( ! function_exists( 'is_store_notice_showing' ) ) {
* @return bool
*/
function is_store_notice_showing() {
return 'no' !== get_option( 'woocommerce_demo_store' );
return 'no' !== get_option( 'woocommerce_demo_store', 'no' );
}
}

View File

@ -710,11 +710,16 @@ function wc_get_image_size( $image_size ) {
if ( 'uncropped' === $cropping ) {
$size['height'] = 9999999999;
$size['crop'] = 0;
} elseif ( 'custom' === $cropping ) {
$width = max( 1, get_option( 'woocommerce_thumbnail_cropping_custom_width', '4' ) );
$height = max( 1, get_option( 'woocommerce_thumbnail_cropping_custom_width', '3' ) );
$size['height'] = round( ( $size['width'] / $width ) * $height );
$size['crop'] = 1;
} else {
$cropping_split = explode( ':', $cropping );
$width_ratio = max( 1, current( $cropping_split ) );
$height_ratio = max( 1, end( $cropping_split ) );
$size['height'] = round( ( $size['width'] / $width_ratio ) * $height_ratio );
$width = max( 1, current( $cropping_split ) );
$height = max( 1, end( $cropping_split ) );
$size['height'] = round( ( $size['width'] / $width ) * $height );
$size['crop'] = 1;
}
$image_size = 'thumbnail';
@ -1495,17 +1500,17 @@ function wc_get_rounding_precision() {
}
/**
* Add precision to a number and return an int.
* Add precision to a number and return a number.
*
* @since 3.2.0
* @param float $value Number to add precision to.
* @param bool $round Should we round after adding precision?.
* @param bool $round If should round after adding precision.
* @return int|float
*/
function wc_add_number_precision( $value, $round = true ) {
$precision = pow( 10, wc_get_price_decimals() );
$value = $value * $precision;
return $round ? intval( round( $value ) ) : $value;
$cent_precision = pow( 10, wc_get_price_decimals() );
$value = $value * $cent_precision;
return $round ? round( $value, wc_get_rounding_precision() - wc_get_price_decimals() ) : $value;
}
/**
@ -1516,8 +1521,8 @@ function wc_add_number_precision( $value, $round = true ) {
* @return float
*/
function wc_remove_number_precision( $value ) {
$precision = pow( 10, wc_get_price_decimals() );
return $value / $precision;
$cent_precision = pow( 10, wc_get_price_decimals() );
return $value / $cent_precision;
}
/**

View File

@ -80,7 +80,7 @@ function wc_sanitize_permalink( $value ) {
$value = '';
}
$value = esc_url_raw( $value );
$value = esc_url_raw( trim( $value ) );
$value = str_replace( 'http://', '', $value );
return untrailingslashit( $value );
}
@ -226,32 +226,46 @@ function wc_trim_zeros( $price ) {
*
* @param double $value Amount to round.
* @param int $precision DP to round. Defaults to wc_get_price_decimals.
* @return double
* @return float
*/
function wc_round_tax_total( $value, $precision = null ) {
$precision = is_null( $precision ) ? wc_get_price_decimals() : absint( $precision );
$precision = is_null( $precision ) ? wc_get_price_decimals() : intval( $precision );
if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
$rounded_tax = round( $value, $precision, wc_get_tax_rounding_mode() );
} elseif ( 2 === wc_get_tax_rounding_mode() ) {
$rounded_tax = wc_legacy_round_half_down( $value, $precision );
} else {
// Fake it in PHP 5.2.
if ( 2 === wc_get_tax_rounding_mode() && strstr( $value, '.' ) ) {
$value = (string) $value;
$value = explode( '.', $value );
$value[1] = substr( $value[1], 0, $precision + 1 );
$value = implode( '.', $value );
if ( substr( $value, -1 ) === '5' ) {
$value = substr( $value, 0, -1 ) . '4';
}
$value = floatval( $value );
}
$rounded_tax = round( $value, $precision );
}
return apply_filters( 'wc_round_tax_total', $rounded_tax, $value, $precision, WC_TAX_ROUNDING_MODE );
}
/**
* Round half down in PHP 5.2.
*
* @since 3.2.6
* @param float $value Value to round.
* @param int $precision Precision to round down to.
* @return float
*/
function wc_legacy_round_half_down( $value, $precision ) {
$value = wc_float_to_string( $value );
if ( false !== strstr( $value, '.' ) ) {
$value = explode( '.', $value );
if ( strlen( $value[1] ) > $precision && substr( $value[1], -1 ) === '5' ) {
$value[1] = substr( $value[1], 0, -1 ) . '4';
}
$value = implode( '.', $value );
}
return round( floatval( $value ), $precision );
}
/**
* Make a refund total negative.
*

View File

@ -43,6 +43,7 @@ function wc_update_product_stock( $product, $stock_quantity = null, $operation =
// Re-read product data after updating stock, then have stock status calculated and saved.
$product_with_stock = wc_get_product( $product_id_with_stock );
$product_with_stock->set_stock_status();
$product_with_stock->set_date_modified( current_time( 'timestamp', true ) );
$product_with_stock->save();
do_action( $product_with_stock->is_type( 'variation' ) ? 'woocommerce_variation_set_stock' : 'woocommerce_product_set_stock', $product_with_stock );

View File

@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
function wc_template_redirect() {
global $wp_query, $wp;
if ( ! empty( $_GET['page_id'] ) && '' === get_option( 'permalink_structure' ) && wc_get_page_id( 'shop' ) === absint( $_GET['page_id'] ) ) { // WPCS: input var ok, CSRF ok.
if ( ! empty( $_GET['page_id'] ) && '' === get_option( 'permalink_structure' ) && wc_get_page_id( 'shop' ) === absint( $_GET['page_id'] ) && get_post_type_archive_link( 'product' ) ) {
// When default permalinks are enabled, redirect shop page to post type archive url.
wp_safe_redirect( get_post_type_archive_link( 'product' ) );
@ -148,54 +148,81 @@ function wc_setup_product_data( $post ) {
}
add_action( 'the_post', 'wc_setup_product_data' );
if ( ! function_exists( 'woocommerce_reset_loop' ) ) {
/**
* Reset the loop's index and columns when we're done outputting a product loop.
*/
function woocommerce_reset_loop() {
$GLOBALS['woocommerce_loop'] = array(
'loop' => '',
'columns' => '',
'name' => '',
);
/**
* Sets up the woocommerce_loop global from the passed args or from the main query.
*
* @since 3.3.0
* @param array $args Args to pass into the global.
*/
function wc_setup_loop( $args = array() ) {
if ( isset( $GLOBALS['woocommerce_loop'] ) ) {
return; // If the loop has already been setup, bail.
}
$default_args = array(
'loop' => 0,
'columns' => wc_get_default_products_per_row(),
'name' => '',
'is_shortcode' => false,
'is_paginated' => true,
'is_search' => false,
'is_filtered' => false,
'total' => 0,
'total_pages' => 0,
'per_page' => 0,
'current_page' => 1,
);
// If this is a main WC query, use global args as defaults.
if ( $GLOBALS['wp_query']->get( 'wc_query' ) ) {
$default_args = array_merge( $default_args, array(
'is_search' => $GLOBALS['wp_query']->is_search(),
'is_filtered' => is_filtered(),
'total' => $GLOBALS['wp_query']->found_posts,
'total_pages' => $GLOBALS['wp_query']->max_num_pages,
'per_page' => $GLOBALS['wp_query']->get( 'posts_per_page' ),
'current_page' => max( 1, $GLOBALS['wp_query']->get( 'paged', 1 ) ),
) );
}
$GLOBALS['woocommerce_loop'] = wp_parse_args( $args, $default_args );
}
add_filter( 'loop_end', 'woocommerce_reset_loop' );
add_action( 'woocommerce_before_shop_loop', 'wc_setup_loop' );
/**
* Products RSS Feed.
* Resets the woocommerce_loop global.
*
* @deprecated 2.6
* @access public
* @since 3.3.0
*/
function wc_products_rss_feed() {
// Product RSS.
if ( is_post_type_archive( 'product' ) || is_singular( 'product' ) ) {
function wc_reset_loop() {
unset( $GLOBALS['woocommerce_loop'] );
}
add_action( 'woocommerce_after_shop_loop', 'woocommerce_reset_loop', 999 );
$feed = get_post_type_archive_feed_link( 'product' );
/**
* Gets a property from the woocommerce_loop global.
*
* @since 3.3.0
* @param string $prop Prop to get.
* @param string $default Default if the prop does not exist.
* @return mixed
*/
function wc_get_loop_prop( $prop, $default = '' ) {
return isset( $GLOBALS['woocommerce_loop'], $GLOBALS['woocommerce_loop'][ $prop ] ) ? $GLOBALS['woocommerce_loop'][ $prop ] : $default;
}
echo '<link rel="alternate" type="application/rss+xml" title="' . esc_attr__( 'New products', 'woocommerce' ) . '" href="' . esc_url( $feed ) . '" />';
} elseif ( is_tax( 'product_cat' ) ) {
$term = get_term_by( 'slug', esc_attr( get_query_var( 'product_cat' ) ), 'product_cat' );
if ( $term ) {
$feed = add_query_arg( 'product_cat', $term->slug, get_post_type_archive_feed_link( 'product' ) );
/* translators: %s: category name */
echo '<link rel="alternate" type="application/rss+xml" title="' . esc_attr( sprintf( __( 'New products added to %s', 'woocommerce' ), $term->name ) ) . '" href="' . esc_url( $feed ) . '" />';
}
} elseif ( is_tax( 'product_tag' ) ) {
$term = get_term_by( 'slug', esc_attr( get_query_var( 'product_tag' ) ), 'product_tag' );
if ( $term ) {
$feed = add_query_arg( 'product_tag', $term->slug, get_post_type_archive_feed_link( 'product' ) );
/* translators: %s: tag name */
echo '<link rel="alternate" type="application/rss+xml" title="' . sprintf( esc_attr__( 'New products tagged %s', 'woocommerce' ), rawurlencode( $term->name ) ) . '" href="' . esc_url( $feed ) . '" />';
}
/**
* Sets a property in the woocommerce_loop global.
*
* @since 3.3.0
* @param string $prop Prop to set.
* @param string $value Value to set.
*/
function wc_set_loop_prop( $prop, $value = '' ) {
if ( ! isset( $GLOBALS['woocommerce_loop'] ) ) {
wc_setup_loop();
}
$GLOBALS['woocommerce_loop'][ $prop ] = $value;
}
/**
@ -277,26 +304,81 @@ function wc_product_cat_class( $class = '', $category = null ) {
}
/**
* Get classname for loops based on $woocommerce_loop global.
* Get the default columns setting - this is how many products will be shown per row in loops.
*
* @since 3.3.0
* @return int
*/
function wc_get_default_products_per_row() {
$columns = get_option( 'woocommerce_catalog_columns', 3 );
// Theme support.
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0] : false;
if ( isset( $theme_support['product_grid']['min_columns'] ) && $columns < $theme_support['product_grid']['min_columns'] ) {
$columns = $theme_support['product_grid']['min_columns'];
update_option( 'woocommerce_catalog_columns', $columns );
} elseif ( ! empty( $theme_support['product_grid']['max_columns'] ) && $columns > $theme_support['product_grid']['max_columns'] ) {
$columns = $theme_support['product_grid']['max_columns'];
update_option( 'woocommerce_catalog_columns', $columns );
}
// Legacy filter.
if ( has_filter( 'loop_shop_columns' ) ) {
$columns = apply_filters( 'loop_shop_columns', $columns );
}
return absint( $columns );
}
/**
* Get the default rows setting - this is how many product rows will be shown in loops.
*
* @since 3.3.0
* @return int
*/
function wc_get_default_product_rows_per_page() {
$rows = absint( get_option( 'woocommerce_catalog_rows', 4 ) );
// Theme support.
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0] : false;
if ( isset( $theme_support['product_grid']['min_rows'] ) && $rows < $theme_support['product_grid']['min_rows'] ) {
$rows = $theme_support['product_grid']['min_rows'];
update_option( 'woocommerce_catalog_rows', $rows );
} elseif ( ! empty( $theme_support['product_grid']['max_rows'] ) && $rows > $theme_support['product_grid']['max_rows'] ) {
$rows = $theme_support['product_grid']['max_rows'];
update_option( 'woocommerce_catalog_rows', $rows );
}
return $rows;
}
/**
* Get classname for woocommerce loops.
*
* @since 2.6.0
* @return string
*/
function wc_get_loop_class() {
global $woocommerce_loop;
$loop_index = wc_get_loop_prop( 'loop', 0 );
$columns = wc_get_loop_prop( 'columns', wc_get_default_products_per_row() );
$woocommerce_loop['loop'] = ! empty( $woocommerce_loop['loop'] ) ? $woocommerce_loop['loop'] + 1 : 1;
$woocommerce_loop['columns'] = max( 1, ! empty( $woocommerce_loop['columns'] ) ? $woocommerce_loop['columns'] : apply_filters( 'loop_shop_columns', 4 ) );
$loop_index ++;
wc_set_loop_prop( 'loop', $loop_index );
if ( 0 === ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 === $woocommerce_loop['columns'] ) {
if ( 0 === ( $loop_index - 1 ) % $columns || 1 === $columns ) {
return 'first';
} elseif ( 0 === $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) {
} elseif ( 0 === $loop_index % $columns ) {
return 'last';
} else {
return '';
}
}
/**
* Get the classes for the product cat div.
*
@ -459,30 +541,22 @@ if ( ! function_exists( 'woocommerce_content' ) ) {
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action( 'woocommerce_after_shop_loop' ); ?>
<?php
elseif ( ! woocommerce_product_subcategories( array(
'before' => woocommerce_product_loop_start( false ),
'after' => woocommerce_product_loop_end( false ),
) ) ) :
?>
<?php else : ?>
<?php do_action( 'woocommerce_no_products_found' ); ?>
<?php
endif;
}
}
}
@ -593,12 +667,17 @@ if ( ! function_exists( 'woocommerce_product_loop_start' ) ) {
*/
function woocommerce_product_loop_start( $echo = true ) {
ob_start();
$GLOBALS['woocommerce_loop']['loop'] = 0;
wc_set_loop_prop( 'loop', 0 );
wc_get_template( 'loop/loop-start.php' );
$loop_start = apply_filters( 'woocommerce_product_loop_start', ob_get_clean() );
if ( $echo ) {
echo ob_get_clean(); // WPCS: XSS ok.
echo $loop_start; // WPCS: XSS ok.
} else {
return ob_get_clean();
return $loop_start;
}
}
}
@ -616,10 +695,12 @@ if ( ! function_exists( 'woocommerce_product_loop_end' ) ) {
wc_get_template( 'loop/loop-end.php' );
$loop_end = apply_filters( 'woocommerce_product_loop_end', ob_get_clean() );
if ( $echo ) {
echo ob_get_clean(); // WPCS: XSS ok.
echo $loop_end; // WPCS: XSS ok.
} else {
return ob_get_clean();
return $loop_end;
}
}
}
@ -819,7 +900,16 @@ if ( ! function_exists( 'woocommerce_result_count' ) ) {
* Output the result count text (Showing x - x of x results).
*/
function woocommerce_result_count() {
wc_get_template( 'loop/result-count.php' );
if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
return;
}
$args = array(
'total' => wc_get_loop_prop( 'total' ),
'per_page' => wc_get_loop_prop( 'per_page' ),
'current' => wc_get_loop_prop( 'current_page' ),
);
wc_get_template( 'loop/result-count.php', $args );
}
}
@ -829,13 +919,10 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
* Output the product sorting options.
*/
function woocommerce_catalog_ordering() {
global $wp_query;
if ( 1 === (int) $wp_query->found_posts || ! woocommerce_products_will_display() ) {
if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
return;
}
$orderby = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( $_GET['orderby'] ) ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); // WPCS: input var ok, CSRF ok.
$orderby = isset( $_GET['orderby'] ) ? wc_clean( wp_unslash( $_GET['orderby'] ) ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
$show_default_orderby = 'menu_order' === apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
$catalog_orderby_options = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
@ -846,10 +933,8 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
'price-desc' => __( 'Sort by price: high to low', 'woocommerce' ),
) );
if ( $wp_query->is_search() ) {
$catalog_orderby_options = array_merge( array(
'relevance' => __( 'Relevance', 'woocommerce' ),
), $catalog_orderby_options );
if ( wc_get_loop_prop( 'is_search' ) ) {
$catalog_orderby_options = array_merge( array( 'relevance' => __( 'Relevance', 'woocommerce' ) ), $catalog_orderby_options );
unset( $catalog_orderby_options['menu_order'] );
if ( 'menu_order' === $orderby ) {
$orderby = 'relevance';
@ -875,10 +960,25 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
if ( ! function_exists( 'woocommerce_pagination' ) ) {
/**
* Output the pagination.
*/
* Output the pagination. */
function woocommerce_pagination() {
wc_get_template( 'loop/pagination.php' );
if ( ! wc_get_loop_prop( 'is_paginated' ) || ! woocommerce_products_will_display() ) {
return;
}
$args = array(
'total' => wc_get_loop_prop( 'total_pages' ),
'current' => wc_get_loop_prop( 'current_page' ),
);
if ( wc_get_loop_prop( 'is_shortcode' ) ) {
$args['base'] = esc_url_raw( add_query_arg( 'product-page', '%#%', false ) );
$args['format'] = '?product-page = %#%';
} else {
$args['base'] = esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
$args['format'] = '';
}
wc_get_template( 'loop/pagination.php', $args );
}
}
@ -1127,18 +1227,6 @@ if ( ! function_exists( 'woocommerce_product_additional_information_tab' ) ) {
wc_get_template( 'single-product/tabs/additional-information.php' );
}
}
if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
/**
* Output the reviews tab content.
*
* @deprecated 2.4.0 Unused.
*/
function woocommerce_product_reviews_tab() {
wc_deprecated_function( 'woocommerce_product_reviews_tab', '2.4' );
}
}
if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {
/**
@ -1313,7 +1401,7 @@ if ( ! function_exists( 'woocommerce_related_products' ) ) {
* @param array $args Provided arguments.
*/
function woocommerce_related_products( $args = array() ) {
global $product, $woocommerce_loop;
global $product;
if ( ! $product ) {
return;
@ -1335,8 +1423,8 @@ if ( ! function_exists( 'woocommerce_related_products' ) ) {
$args['related_products'] = wc_products_array_orderby( $args['related_products'], $args['orderby'], $args['order'] );
// Set global loop values.
$woocommerce_loop['name'] = 'related';
$woocommerce_loop['columns'] = apply_filters( 'woocommerce_related_products_columns', $args['columns'] );
wc_set_loop_prop( 'name', 'related' );
wc_set_loop_prop( 'columns', apply_filters( 'woocommerce_related_products_columns', $args['columns'] ) );
wc_get_template( 'single-product/related.php', $args );
}
@ -1353,7 +1441,7 @@ if ( ! function_exists( 'woocommerce_upsell_display' ) ) {
* @param string $order Sort direction.
*/
function woocommerce_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' ) {
global $product, $woocommerce_loop;
global $product;
if ( ! $product ) {
return;
@ -1365,8 +1453,9 @@ if ( ! function_exists( 'woocommerce_upsell_display' ) ) {
'orderby' => $orderby,
'columns' => $columns,
) );
$woocommerce_loop['name'] = 'up-sells';
$woocommerce_loop['columns'] = apply_filters( 'woocommerce_upsells_columns', isset( $args['columns'] ) ? $args['columns'] : $columns );
wc_set_loop_prop( 'name', 'up-sells' );
wc_set_loop_prop( 'columns', apply_filters( 'woocommerce_upsells_columns', isset( $args['columns'] ) ? $args['columns'] : $columns ) );
$orderby = apply_filters( 'woocommerce_upsells_orderby', isset( $args['orderby'] ) ? $args['orderby'] : $orderby );
$limit = apply_filters( 'woocommerce_upsells_total', isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : $limit );
@ -1421,15 +1510,13 @@ if ( ! function_exists( 'woocommerce_cross_sell_display' ) ) {
* @param string $order (default: 'desc').
*/
function woocommerce_cross_sell_display( $limit = 2, $columns = 2, $orderby = 'rand', $order = 'desc' ) {
global $woocommerce_loop;
if ( is_checkout() ) {
return;
}
// Get visible cross sells then sort them at random.
$cross_sells = array_filter( array_map( 'wc_get_product', WC()->cart->get_cross_sells() ), 'wc_products_array_filter_visible' );
$woocommerce_loop['name'] = 'cross-sells';
$woocommerce_loop['columns'] = apply_filters( 'woocommerce_cross_sells_columns', $columns );
wc_set_loop_prop( 'name', 'cross-sells' );
wc_set_loop_prop( 'columns', apply_filters( 'woocommerce_cross_sells_columns', $columns ) );
// Handle orderby and limit results.
$orderby = apply_filters( 'woocommerce_cross_sells_orderby', $orderby );
@ -1626,73 +1713,51 @@ if ( ! function_exists( 'woocommerce_products_will_display' ) ) {
* @return bool
*/
function woocommerce_products_will_display() {
global $wpdb;
return 0 < wc_get_loop_prop( 'total', 0 );
}
}
if ( ! function_exists( 'woocommerce_maybe_show_product_subcategories' ) ) {
/**
* Maybe display categories before, or instead of, a product loop.
*
* @since 3.3.0
* @param string $loop_html HTML.
* @return string
*/
function woocommerce_maybe_show_product_subcategories( $loop_html ) {
// Don't show when filtering, searching or when on page > 1.
if ( 1 < wc_get_loop_prop( 'current_page' ) || wc_get_loop_prop( 'is_search' ) || wc_get_loop_prop( 'is_filtered' ) ) {
return $loop_html;
}
$parent_id = 0;
$display_type = '';
// Check categories are enabled and see what level to query.
if ( is_shop() ) {
return 'subcategories' !== get_option( 'woocommerce_shop_page_display' ) || is_search();
$display_type = get_option( 'woocommerce_shop_page_display', '' );
} elseif ( is_product_category() ) {
$parent_id = get_queried_object_id();
$display_type = get_woocommerce_term_meta( $parent_id, 'display_type', true );
$display_type = '' === $display_type ? get_option( 'woocommerce_category_archive_display', '' ) : $display_type;
}
if ( ! is_product_taxonomy() ) {
return false;
}
// If displaying categories, append to the loop.
if ( '' !== $display_type ) {
ob_start();
woocommerce_product_subcategories( array(
'parent_id' => $parent_id,
) );
$loop_html .= ob_get_clean();
if ( is_search() || is_filtered() || is_paged() ) {
return true;
}
$term = get_queried_object();
if ( is_product_category() ) {
switch ( get_woocommerce_term_meta( $term->term_id, 'display_type', true ) ) {
case 'subcategories':
// Nothing - we want to continue to see if there are products/subcats.
break;
case 'products':
case 'both':
return true;
default:
// Default - no setting.
if ( get_option( 'woocommerce_category_archive_display' ) !== 'subcategories' ) {
return true;
}
break;
if ( 'subcategories' === $display_type ) {
wc_set_loop_prop( 'total', 0 );
}
}
// Begin subcategory logic.
if ( empty( $term->term_id ) || empty( $term->taxonomy ) ) {
return true;
}
$transient_name = 'wc_products_will_display_' . $term->term_id . '_' . WC_Cache_Helper::get_transient_version( 'product_query' );
$products_will_display = get_transient( $transient_name );
if ( false === $products_will_display ) {
$has_children = $wpdb->get_col( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d AND taxonomy = %s", $term->term_id, $term->taxonomy ) ); // WPCS: db call ok, cache ok.
if ( $has_children ) {
// Check terms have products inside - parents first. If products are found inside, subcats will be shown instead of products so we can return false.
if ( count( get_objects_in_term( $has_children, $term->taxonomy ) ) > 0 ) {
$products_will_display = false;
} else {
// If we get here, the parents were empty so we're forced to check children.
foreach ( $has_children as $term_id ) {
$children = get_term_children( $term_id, $term->taxonomy );
if ( count( get_objects_in_term( $children, $term->taxonomy ) ) > 0 ) {
$products_will_display = false;
break;
}
}
}
} else {
$products_will_display = true;
}
}
set_transient( $transient_name, $products_will_display, DAY_IN_SECONDS * 30 );
return $products_will_display;
return $loop_html;
}
}
@ -1702,57 +1767,18 @@ if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
* Display product sub categories as thumbnails.
*
* @param array $args Arguments.
* @return null|boolean
* @return boolean
*/
function woocommerce_product_subcategories( $args = array() ) {
global $wp_query;
$defaults = array(
'before' => '',
'after' => '',
'force_display' => false,
);
$args = wp_parse_args( $args, $defaults );
extract( $args ); // @codingStandardsIgnoreLine
// Main query only.
if ( ! is_main_query() && ! $force_display ) {
return;
}
// Don't show when filtering, searching or when on page > 1 and ensure we're on a product archive.
if ( is_search() || is_filtered() || is_paged() || ( ! is_product_category() && ! is_shop() ) ) {
return;
}
// Check categories are enabled.
if ( is_shop() && '' === get_option( 'woocommerce_shop_page_display' ) ) {
return;
}
// Find the category + category parent, if applicable.
$term = get_queried_object();
$parent_id = empty( $term->term_id ) ? 0 : $term->term_id;
if ( is_product_category() ) {
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
switch ( $display_type ) {
case 'products':
return;
case '':
if ( '' === get_option( 'woocommerce_category_archive_display' ) ) {
return;
}
break;
}
}
$args = wp_parse_args( $args, array(
'before' => '',
'after' => '',
'parent_id' => 0,
) );
// NOTE: using child_of instead of parent - this is not ideal but due to a WP bug ( https://core.trac.wordpress.org/ticket/15626 ) pad_counts won't work.
$product_categories = get_categories( apply_filters( 'woocommerce_product_subcategories_args', array(
'parent' => $parent_id,
'parent' => $args['parent_id'],
'menu_order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
@ -1761,47 +1787,24 @@ if ( ! function_exists( 'woocommerce_product_subcategories' ) ) {
) ) );
if ( apply_filters( 'woocommerce_product_subcategories_hide_empty', true ) ) {
$product_categories = wp_list_filter( $product_categories, array(
'count' => 0,
), 'NOT' );
$product_categories = wp_list_filter( $product_categories, array( 'count' => 0 ), 'NOT' );
}
if ( $product_categories ) {
echo wp_kses_post( $before );
foreach ( $product_categories as $category ) {
wc_get_template( 'content-product_cat.php', array(
'category' => $category,
) );
}
// If we are hiding products disable the loop and pagination.
if ( is_product_category() ) {
$display_type = get_woocommerce_term_meta( $term->term_id, 'display_type', true );
switch ( $display_type ) {
case 'subcategories':
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
break;
case '':
if ( 'subcategories' === get_option( 'woocommerce_category_archive_display' ) ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
break;
}
}
if ( is_shop() && 'subcategories' === get_option( 'woocommerce_shop_page_display' ) ) {
$wp_query->post_count = 0;
$wp_query->max_num_pages = 0;
}
echo wp_kses_post( $after );
return true;
if ( ! $product_categories ) {
return false;
}
echo wp_kses_post( $args['before'] );
foreach ( $product_categories as $category ) {
wc_get_template( 'content-product_cat.php', array(
'category' => $category,
) );
}
echo wp_kses_post( $args['after'] );
return true;
}
}
@ -2694,3 +2697,35 @@ add_action( 'wp_head', 'wc_page_noindex' );
function wc_get_theme_slug_for_templates() {
return apply_filters( 'woocommerce_theme_slug_for_templates', get_option( 'template' ) );
}
/**
* Products RSS Feed.
*
* @deprecated 2.6
*/
function wc_products_rss_feed() {
wc_deprecated_function( 'wc_products_rss_feed', '2.6' );
}
if ( ! function_exists( 'woocommerce_reset_loop' ) ) {
/**
* Reset the loop's index and columns when we're done outputting a product loop.
*
* @deprecated 3.3
*/
function woocommerce_reset_loop() {
wc_reset_loop();
}
}
if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
/**
* Output the reviews tab content.
*
* @deprecated 2.4.0 Unused.
*/
function woocommerce_product_reviews_tab() {
wc_deprecated_function( 'woocommerce_product_reviews_tab', '2.4' );
}
}

View File

@ -66,6 +66,11 @@ add_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
/**
* Product loop start.
*/
add_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' );
/**
* Products Loop.
*

View File

@ -1519,6 +1519,7 @@ function wc_update_330_webhooks() {
}
unregister_post_type( 'shop_webhook' );
}
/**
* Assign default cat to all products with no cats.
@ -1592,3 +1593,11 @@ function wc_update_330_product_stock_status() {
function wc_update_330_db_version() {
WC_Install::update_db_version( '3.3.0' );
}
/**
* Clear addons page transients
*/
function wc_update_330_clear_transients() {
delete_transient( 'wc_addons_sections' );
delete_transient( 'wc_addons_featured' );
}

View File

@ -34,73 +34,6 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
parent::__construct();
}
/**
* Get current page URL for layered nav items.
*
* @return string
*/
protected function get_page_base_url() {
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$link = get_post_type_archive_link( 'product' );
} elseif ( is_product_category() ) {
$link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
} elseif ( is_product_tag() ) {
$link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
} else {
$queried_object = get_queried_object();
$link = get_term_link( $queried_object->slug, $queried_object->taxonomy );
}
// Min/Max
if ( isset( $_GET['min_price'] ) ) {
$link = add_query_arg( 'min_price', wc_clean( $_GET['min_price'] ), $link );
}
if ( isset( $_GET['max_price'] ) ) {
$link = add_query_arg( 'max_price', wc_clean( $_GET['max_price'] ), $link );
}
// Order by
if ( isset( $_GET['orderby'] ) ) {
$link = add_query_arg( 'orderby', wc_clean( $_GET['orderby'] ), $link );
}
/**
* Search Arg.
* To support quote characters, first they are decoded from &quot; entities, then URL encoded.
*/
if ( get_search_query() ) {
$link = add_query_arg( 's', rawurlencode( htmlspecialchars_decode( get_search_query( false ) ) ), $link );
}
// Post Type Arg
if ( isset( $_GET['post_type'] ) ) {
$link = add_query_arg( 'post_type', wc_clean( $_GET['post_type'] ), $link );
}
// Min Rating Arg
if ( isset( $_GET['rating_filter'] ) ) {
$link = add_query_arg( 'rating_filter', wc_clean( $_GET['rating_filter'] ), $link );
}
// All current filters
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) {
foreach ( $_chosen_attributes as $name => $data ) {
$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
if ( ! empty( $data['terms'] ) ) {
$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
}
if ( 'or' == $data['query_type'] ) {
$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
}
}
}
return $link;
}
/**
* Output widget.
*
@ -109,7 +42,7 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
* @param array $instance
*/
public function widget( $args, $instance ) {
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
if ( ! is_shop() && ! is_product_taxonomy() ) {
return;
}

View File

@ -115,7 +115,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
* @param array $instance Instance.
*/
public function widget( $args, $instance ) {
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
if ( ! is_shop() && ! is_product_taxonomy() ) {
return;
}
@ -316,78 +316,6 @@ class WC_Widget_Layered_Nav extends WC_Widget {
return $found;
}
/**
* Get current page URL for layered nav items.
*
* @param string $taxonomy Taxonomy.
*
* @return string
*/
protected function get_page_base_url( $taxonomy ) {
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$link = get_post_type_archive_link( 'product' );
} elseif ( is_product_category() ) {
$link = get_term_link( get_query_var( 'product_cat' ), 'product_cat' );
} elseif ( is_product_tag() ) {
$link = get_term_link( get_query_var( 'product_tag' ), 'product_tag' );
} else {
$queried_object = get_queried_object();
$link = get_term_link( $queried_object->slug, $queried_object->taxonomy );
}
// Min/Max.
if ( isset( $_GET['min_price'] ) ) {
$link = add_query_arg( 'min_price', wc_clean( wp_unslash( $_GET['min_price'] ) ), $link );
}
if ( isset( $_GET['max_price'] ) ) {
$link = add_query_arg( 'max_price', wc_clean( wp_unslash( $_GET['max_price'] ) ), $link );
}
// Order by.
if ( isset( $_GET['orderby'] ) ) {
$link = add_query_arg( 'orderby', wc_clean( wp_unslash( $_GET['orderby'] ) ), $link );
}
/**
* Search Arg.
* To support quote characters, first they are decoded from &quot; entities, then URL encoded.
*/
if ( get_search_query() ) {
$link = add_query_arg( 's', rawurlencode( htmlspecialchars_decode( get_search_query( false ) ) ), $link );
}
// Post Type Arg.
if ( isset( $_GET['post_type'] ) ) {
$link = add_query_arg( 'post_type', wc_clean( wp_unslash( $_GET['post_type'] ) ), $link );
}
// Min Rating Arg.
if ( isset( $_GET['rating_filter'] ) ) {
$link = add_query_arg( 'rating_filter', wc_clean( wp_unslash( $_GET['rating_filter'] ) ), $link );
}
// All current filters.
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) {
foreach ( $_chosen_attributes as $name => $data ) {
if ( $name === $taxonomy ) {
continue;
}
$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
if ( ! empty( $data['terms'] ) ) {
$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
}
if ( 'or' == $data['query_type'] ) {
$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
}
}
}
return $link;
}
/**
* Count products within certain terms, taking the main WP query into consideration.
*
@ -496,7 +424,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$current_filter[] = $term->slug;
}
$link = $this->get_page_base_url( $taxonomy );
$link = remove_query_arg( $filter_name, $this->get_page_base_url() );
// Add current filters to URL.
foreach ( $current_filter as $key => $value ) {

View File

@ -60,13 +60,13 @@ class WC_Widget_Price_Filter extends WC_Widget {
* @param array $instance
*/
public function widget( $args, $instance ) {
global $wp, $wp_the_query;
global $wp;
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
if ( ! is_shop() && ! is_product_taxonomy() ) {
return;
}
if ( ! $wp_the_query->post_count ) {
if ( ! wc()->query->get_main_query()->post_count ) {
return;
}
@ -134,9 +134,9 @@ class WC_Widget_Price_Filter extends WC_Widget {
* @return int
*/
protected function get_filtered_price() {
global $wpdb, $wp_the_query;
global $wpdb;
$args = $wp_the_query->query_vars;
$args = wc()->query->get_main_query()->query_vars;
$tax_query = isset( $args['tax_query'] ) ? $args['tax_query'] : array();
$meta_query = isset( $args['meta_query'] ) ? $args['meta_query'] : array();

View File

@ -34,62 +34,6 @@ class WC_Widget_Rating_Filter extends WC_Widget {
parent::__construct();
}
/**
* Get current page URL for layered nav items.
* @return string
*/
protected function get_page_base_url() {
if ( defined( 'SHOP_IS_ON_FRONT' ) ) {
$link = home_url();
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$link = get_post_type_archive_link( 'product' );
} else {
$link = get_term_link( get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
}
// Min/Max
if ( isset( $_GET['min_price'] ) ) {
$link = add_query_arg( 'min_price', wc_clean( $_GET['min_price'] ), $link );
}
if ( isset( $_GET['max_price'] ) ) {
$link = add_query_arg( 'max_price', wc_clean( $_GET['max_price'] ), $link );
}
// Order by
if ( isset( $_GET['orderby'] ) ) {
$link = add_query_arg( 'orderby', wc_clean( $_GET['orderby'] ), $link );
}
/**
* Search Arg.
* To support quote characters, first they are decoded from &quot; entities, then URL encoded.
*/
if ( get_search_query() ) {
$link = add_query_arg( 's', rawurlencode( htmlspecialchars_decode( get_search_query() ) ), $link );
}
// Post Type Arg
if ( isset( $_GET['post_type'] ) ) {
$link = add_query_arg( 'post_type', wc_clean( $_GET['post_type'] ), $link );
}
// All current filters
if ( $_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes() ) {
foreach ( $_chosen_attributes as $name => $data ) {
$filter_name = sanitize_title( str_replace( 'pa_', '', $name ) );
if ( ! empty( $data['terms'] ) ) {
$link = add_query_arg( 'filter_' . $filter_name, implode( ',', $data['terms'] ), $link );
}
if ( 'or' == $data['query_type'] ) {
$link = add_query_arg( 'query_type_' . $filter_name, 'or', $link );
}
}
}
return $link;
}
/**
* Count products after other filters have occurred by adjusting the main query.
* @param int $rating
@ -145,13 +89,11 @@ class WC_Widget_Rating_Filter extends WC_Widget {
* @param array $instance
*/
public function widget( $args, $instance ) {
global $wp_the_query;
if ( ! is_post_type_archive( 'product' ) && ! is_tax( get_object_taxonomies( 'product' ) ) ) {
if ( ! is_shop() && ! is_product_taxonomy() ) {
return;
}
if ( ! $wp_the_query->post_count ) {
if ( ! wc()->query->get_main_query()->post_count ) {
return;
}

View File

@ -33,7 +33,7 @@
</rule>
<rule ref="WordPress.VIP.ValidatedSanitizedInput">
<properties>
<property name="customSanitizingFunctions" type="array" value="wc_clean,wc_sanitize_tooltip,wc_format_decimal,wc_stock_amount" />
<property name="customSanitizingFunctions" type="array" value="wc_clean,wc_sanitize_tooltip,wc_format_decimal,wc_stock_amount,wc_sanitize_permalink" />
</properties>
</rule>
<rule ref="WordPress.XSS.EscapeOutput">

View File

@ -13,118 +13,100 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}
get_header( 'shop' ); ?>
get_header( 'shop' );
/**
* Hook: woocommerce_before_main_content.
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
* @hooked WC_Structured_Data::generate_website_data() - 30
*/
do_action( 'woocommerce_before_main_content' );
?>
<header class="woocommerce-products-header">
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
<h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
<?php
/**
* woocommerce_before_main_content hook.
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
* @hooked WC_Structured_Data::generate_website_data() - 30
*/
do_action( 'woocommerce_before_main_content' );
/**
* Hook: woocommerce_archive_description.
*
* @hooked woocommerce_taxonomy_archive_description - 10
* @hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
</header>
<?php
<header class="woocommerce-products-header">
if ( have_posts() ) :
<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
/**
* Hook: woocommerce_before_shop_loop.
*
* @hooked wc_print_notices - 10
* @hooked woocommerce_result_count - 20
* @hooked woocommerce_catalog_ordering - 30
*/
do_action( 'woocommerce_before_shop_loop' );
<h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
woocommerce_product_loop_start();
<?php endif; ?>
while ( have_posts() ) :
the_post();
<?php
/**
* woocommerce_archive_description hook.
*
* @hooked woocommerce_taxonomy_archive_description - 10
* @hooked woocommerce_product_archive_description - 10
*/
do_action( 'woocommerce_archive_description' );
?>
</header>
<?php if ( have_posts() ) : ?>
<?php
/**
* woocommerce_before_shop_loop hook.
*
* @hooked wc_print_notices - 10
* @hooked woocommerce_result_count - 20
* @hooked woocommerce_catalog_ordering - 30
*/
do_action( 'woocommerce_before_shop_loop' );
?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/**
* woocommerce_shop_loop hook.
*
* @hooked WC_Structured_Data::generate_product_data() - 10
*/
do_action( 'woocommerce_shop_loop' );
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php
/**
* woocommerce_after_shop_loop hook.
*
* @hooked woocommerce_pagination - 10
*/
do_action( 'woocommerce_after_shop_loop' );
?>
<?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>
<?php
/**
* woocommerce_no_products_found hook.
*
* @hooked wc_no_products_found - 10
*/
do_action( 'woocommerce_no_products_found' );
?>
<?php endif; ?>
<?php
/**
* woocommerce_after_main_content hook.
* Hook: woocommerce_shop_loop.
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
* @hooked WC_Structured_Data::generate_product_data() - 10
*/
do_action( 'woocommerce_after_main_content' );
?>
do_action( 'woocommerce_shop_loop' );
<?php
/**
* woocommerce_sidebar hook.
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
?>
wc_get_template_part( 'content', 'product' );
endwhile;
<?php get_footer( 'shop' ); ?>
woocommerce_product_loop_end();
/**
* Hook: woocommerce_after_shop_loop.
*
* @hooked woocommerce_pagination - 10
*/
do_action( 'woocommerce_after_shop_loop' );
else :
/**
* Hook: woocommerce_no_products_found.
*
* @hooked wc_no_products_found - 10
*/
do_action( 'woocommerce_no_products_found' );
endif;
/**
* Hook: woocommerce_after_main_content.
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
/**
* Hook: woocommerce_sidebar.
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
get_footer( 'shop' );

View File

@ -13,7 +13,7 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
* @version 3.3.0
*/
?>
<ul class="products">
<ul class="products columns-<?php echo esc_attr( wc_get_loop_prop( 'columns' ) ); ?>">

View File

@ -13,11 +13,11 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.2.0
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}
?>
@ -27,5 +27,6 @@ if ( ! defined( 'ABSPATH' ) ) {
<option value="<?php echo esc_attr( $id ); ?>" <?php selected( $orderby, $id ); ?>><?php echo esc_html( $name ); ?></option>
<?php endforeach; ?>
</select>
<?php wc_query_string_form_fields( null, array( 'orderby', 'submit' ) ); ?>
<input type="hidden" name="paged" value="1" />
<?php wc_query_string_form_fields( null, array( 'orderby', 'submit', 'paged' ) ); ?>
</form>

View File

@ -13,27 +13,25 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.2.2
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}
global $wp_query;
if ( $wp_query->max_num_pages <= 1 ) {
if ( $total <= 1 ) {
return;
}
?>
<nav class="woocommerce-pagination">
<?php
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ),
'format' => '',
'base' => $base,
'format' => $format,
'add_args' => false,
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages,
'current' => max( 1, $current ),
'total' => $total,
'prev_text' => '&larr;',
'next_text' => '&rarr;',
'type' => 'list',

View File

@ -15,31 +15,21 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 3.0.0
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $wp_query;
if ( ! woocommerce_products_will_display() ) {
return;
exit;
}
?>
<p class="woocommerce-result-count">
<?php
$paged = max( 1, $wp_query->get( 'paged' ) );
$per_page = $wp_query->get( 'posts_per_page' );
$total = $wp_query->found_posts;
$first = ( $per_page * $paged ) - $per_page + 1;
$last = min( $total, $wp_query->get( 'posts_per_page' ) * $paged );
if ( $total <= $per_page || -1 === $per_page ) {
/* translators: %d: total results */
printf( _n( 'Showing the single result', 'Showing all %d results', $total, 'woocommerce' ), $total );
} else {
$first = ( $per_page * $current ) - $per_page + 1;
$last = min( $total, $per_page * $current );
/* translators: 1: first result 2: last result 3: total results */
printf( _nx( 'Showing the single result', 'Showing %1$d&ndash;%2$d of %3$d results', $total, 'with first and last result', 'woocommerce' ), $first, $last, $total );
}

View File

@ -165,32 +165,6 @@ class Settings extends WC_REST_Unit_Test_Case {
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/invalid' ) );
$this->assertEquals( 404, $response->get_status() );
// test getting a valid group
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/general' ) );
$data = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertContains( array(
'id' => 'woocommerce_demo_store',
'label' => 'Store notice',
'description' => 'Enable site-wide store notice text',
'type' => 'checkbox',
'default' => 'no',
'value' => 'no',
'_links' => array(
'self' => array(
array(
'href' => rest_url( '/wc/v2/settings/general/woocommerce_demo_store' ),
),
),
'collection' => array(
array(
'href' => rest_url( '/wc/v2/settings/general' ),
),
),
),
), $data );
// test getting a valid group with settings attached to it
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/settings/test' ) );
$data = $response->get_data();

View File

@ -301,7 +301,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
WC()->cart->calculate_totals();
$this->assertEquals( '8.33', wc_format_decimal( WC()->cart->get_subtotal(), 2 ) );
$this->assertEquals( '0.83', wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
$this->assertEquals( '1.50', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
$this->assertEquals( '1.50', wc_format_decimal( WC()->cart->get_total_tax(), 2 ), WC()->cart->get_total_tax() );
$this->assertEquals( '8.99', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
WC()->cart->remove_coupons();
@ -396,6 +396,213 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
return 'US';
}
/**
* Test a rounding issue on prices that are entered inclusive tax and shipping is used.
* See: #17970.
*
* @since 3.2.6
*/
public function test_inclusive_tax_rounding() {
global $wpdb;
// Store is set to enter product prices inclusive tax.
update_option( 'woocommerce_prices_include_tax', 'yes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
// 19% tax.
$tax_rate = array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '19.0000',
'tax_rate_name' => 'VAT',
'tax_rate_priority' => '1',
'tax_rate_compound' => '0',
'tax_rate_shipping' => '1',
'tax_rate_order' => '1',
'tax_rate_class' => '',
);
WC_Tax::_insert_tax_rate( $tax_rate );
// Create a flat rate method.
$flat_rate_settings = array(
'enabled' => 'yes',
'title' => 'Flat rate',
'availability' => 'all',
'countries' => '',
'tax_status' => 'taxable',
'cost' => '4.12',
);
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
update_option( 'woocommerce_flat_rate', array() );
WC_Cache_Helper::get_transient_version( 'shipping', true );
WC()->shipping->load_shipping_methods();
// We need this to have the calculate_totals() method calculate totals.
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}
// Create the product and add it to the cart.
$product = new WC_Product_Simple;
$product->set_regular_price( '149.14' );
$product->save();
WC()->cart->add_to_cart( $product->get_id(), 1 );
// Set the flat_rate shipping method
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
WC()->cart->calculate_totals();
$this->assertEquals( '154.04', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
$this->assertEquals( '24.59', wc_format_decimal( WC()->cart->get_total_tax(), 2 ) );
// Clean up.
WC()->cart->empty_cart();
WC_Helper_Product::delete_product( $product->get_id() );
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" );
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
// Delete the flat rate method
WC()->session->set( 'chosen_shipping_methods', array() );
delete_option( 'woocommerce_flat_rate_settings' );
delete_option( 'woocommerce_flat_rate' );
WC_Cache_Helper::get_transient_version( 'shipping', true );
WC()->shipping->unregister_shipping_methods();
}
/**
* Test a rounding issue on prices that are entered exclusive tax.
* See: #17970.
*
* @since 3.2.6
*/
public function test_exclusive_tax_rounding() {
global $wpdb;
// todo remove this line when previous test stops failing.
WC()->cart->empty_cart();
// Store is set to enter product prices excluding tax.
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
// 20% tax.
$tax_rate = array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '20.0000',
'tax_rate_name' => 'VAT',
'tax_rate_priority' => '1',
'tax_rate_compound' => '0',
'tax_rate_shipping' => '0',
'tax_rate_order' => '1',
'tax_rate_class' => '',
);
WC_Tax::_insert_tax_rate( $tax_rate );
// Add 2 products whose retail prices (inc tax) are: £65, £50.
// Their net prices are therefore: £54.1666667 and £41.6666667.
$product1 = new WC_Product_Simple;
$product1->set_regular_price( '54.1666667' );
$product1->save();
$product2 = new WC_Product_Simple;
$product2->set_regular_price( '41.6666667' );
$product2->save();
WC()->cart->add_to_cart( $product1->get_id(), 1 );
WC()->cart->add_to_cart( $product2->get_id(), 1 );
WC()->cart->calculate_totals();
$this->assertEquals( '115.00', wc_format_decimal( WC()->cart->get_total( 'edit' ), 2 ) );
// Clean up.
WC()->cart->empty_cart();
WC_Helper_Product::delete_product( $product1->get_id() );
WC_Helper_Product::delete_product( $product2->get_id() );
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" );
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
}
/**
* Test a rounding issue on prices and totals that are entered exclusive tax.
* See: #17647.
*
* @since 3.2.6
*/
public function test_exclusive_tax_rounding_and_totals() {
global $wpdb;
WC()->cart->empty_cart();
WC()->cart->remove_coupons();
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" );
$product_data = array(
// price, quantity.
array( 2.13, 1 ),
array( 2.55, 0.5 ),
array( 39, 1 ),
array( 1.76, 1 ),
);
foreach ( $product_data as $data ) {
$product = new WC_Product_Simple();
$product->set_regular_price( $data[0] );
$product->save();
$products[] = array( $product, $data[1] );
}
$tax_rate = array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '5.5',
'tax_rate_name' => 'TAX',
'tax_rate_priority' => '1',
'tax_rate_compound' => '0',
'tax_rate_shipping' => '1',
'tax_rate_order' => '1',
'tax_rate_class' => '',
);
WC_Tax::_insert_tax_rate( $tax_rate );
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_tax_round_at_subtotal', 'no' );
foreach ( $products as $data ) {
WC()->cart->add_to_cart( $data[0]->get_id(), $data[1] );
}
// We need this to have the calculate_totals() method calculate totals.
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}
WC()->cart->calculate_totals();
$cart_totals = WC()->cart->get_totals();
$this->assertEquals( '2.44', wc_format_decimal( $cart_totals['total_tax'], 2 ) );
$this->assertEquals( '2.44', wc_format_decimal( $cart_totals['cart_contents_tax'], 2 ) );
$this->assertEquals( '44.17', wc_format_decimal( $cart_totals['cart_contents_total'], 2 ) );
$this->assertEquals( '46.61', wc_format_decimal( $cart_totals['total'], 2 ) );
// Clean up.
WC()->cart->empty_cart();
foreach ( $products as $data ) {
WC_Helper_Product::delete_product( $data[0]->get_id() );
}
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" );
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
}
/**
* Test get_remove_url.
*

View File

@ -221,15 +221,29 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
/**
* Test wc_round_tax_total().
*
* Note the PHP 5.2 section of wc_round_tax_total() is excluded from test.
* coverage.
*
* @since 2.2
*/
public function test_wc_round_tax_total() {
update_option( 'woocommerce_prices_include_tax', 'no' );
$this->assertEquals( 1.25, wc_round_tax_total( 1.246 ) );
$this->assertEquals( 20, wc_round_tax_total( 19.9997 ) );
$this->assertEquals( 19.99, wc_round_tax_total( 19.99 ) );
$this->assertEquals( 19.99, wc_round_tax_total( 19.99 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.5, 0 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.54, 0 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.546, 0 ) );
update_option( 'woocommerce_prices_include_tax', 'yes' );
$this->assertEquals( 1.25, wc_round_tax_total( 1.246 ) );
$this->assertEquals( 20, wc_round_tax_total( 19.9997 ) );
$this->assertEquals( 19.99, wc_round_tax_total( 19.99 ) );
$this->assertEquals( 19.99, wc_round_tax_total( 19.99 ) );
$this->assertEquals( 82, wc_round_tax_total( 82.5, 0 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.54, 0 ) );
$this->assertEquals( 83, wc_round_tax_total( 82.546, 0 ) );
// Default.
update_option( 'woocommerce_prices_include_tax', 'no' );
}
/**

View File

@ -224,4 +224,41 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
}
}
/**
* A test ensuring get_price_html works independently for issue #18037.
*/
public function test_multiple_get_price_html_calls() {
// Set up 3 products with differing prices.
$product1 = new WC_Product_Simple();
$product2 = new WC_Product_Simple();
$product3 = new WC_Product_Simple();
$product1->set_regular_price( '10.00' );
$product1->set_sale_price( '7.00' );
$product2->set_regular_price( '20.00' );
$product2->set_sale_price( '16.00' );
$product3->set_regular_price( '50.00' );
$product1_id = $product1->save();
$product2_id = $product2->save();
$product3_id = $product3->save();
$product = wc_get_product( $product1_id );
$this->assertEquals( $product1_id, $product->get_id() );
$this->assertEquals( '<del><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>&#x200e;10.00</span></del> <ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>&#x200e;7.00</span></ins>', $product->get_price_html() );
$product = wc_get_product( $product2_id );
$this->assertEquals( $product2_id, $product->get_id() );
$this->assertEquals( '<del><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>&#x200e;20.00</span></del> <ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>&#x200e;16.00</span></ins>', $product->get_price_html() );
$product = wc_get_product( $product3_id );
$this->assertEquals( $product3_id, $product->get_id() );
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&pound;</span>&#x200e;50.00</span>', $product->get_price_html() );
// Clean up.
$product1->delete();
$product2->delete();
$product3->delete();
}
}

View File

@ -14,7 +14,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$shortcode = new WC_Shortcode_Products();
$expected = array(
'limit' => '-1',
'columns' => '4',
'columns' => '3',
'orderby' => 'title',
'order' => 'ASC',
'ids' => '',
@ -26,6 +26,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'terms_operator' => 'IN',
'visibility' => 'visible',
'class' => '',
'rows' => '',
'page' => 1,
'paginate' => false,
'cache' => true,
'tag' => '',
);
$this->assertEquals( $expected, $shortcode->get_attributes() );
@ -35,7 +40,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
) );
$expected2 = array(
'limit' => '-1',
'columns' => '4',
'columns' => '3',
'orderby' => 'id',
'order' => 'DESC',
'ids' => '',
@ -47,6 +52,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'terms_operator' => 'IN',
'visibility' => 'visible',
'class' => '',
'rows' => '',
'page' => 1,
'paginate' => false,
'cache' => true,
'tag' => '',
);
$this->assertEquals( $expected2, $shortcode2->get_attributes() );
}
@ -67,7 +77,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'no_found_rows' => true,
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'posts_per_page' => '-1',
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'fields' => 'ids',
@ -86,7 +96,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'no_found_rows' => true,
'orderby' => 'id',
'order' => 'DESC',
'posts_per_page' => -1,
'posts_per_page' => '-1',
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'fields' => 'ids',
@ -104,7 +114,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'no_found_rows' => true,
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => -1,
'posts_per_page' => '-1',
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'post__in' => array( '1', '2', '3' ),
@ -122,7 +132,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
$shortcode4 = new WC_Shortcode_Products( array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'menu_order title',
'orderby' => 'title',
'order' => 'ASC',
'category' => 'clothing',
'operator' => 'IN',
@ -132,12 +142,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'orderby' => 'menu_order title',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 12,
'posts_per_page' => '12',
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'meta_key' => '',
'fields' => 'ids',
);
$expected4['tax_query'][] = array(
@ -163,9 +172,9 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'orderby' => 'date',
'orderby' => 'date ID',
'order' => 'DESC',
'posts_per_page' => 12,
'posts_per_page' => '12',
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'fields' => 'ids',
@ -185,7 +194,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'no_found_rows' => true,
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 1,
'posts_per_page' => '1',
'meta_query' => $meta_query,
'tax_query' => $tax_query,
'p' => '1',
@ -281,7 +290,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'orderby' => 'date',
'orderby' => 'date ID',
'order' => 'DESC',
'posts_per_page' => 12,
'meta_query' => $meta_query,

View File

@ -272,7 +272,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
* Next tax would be calced on 100 - 7.8341 = 92.1659.
* 92.1659 - ( 92.1659 / 1.05 ) = 4.38885.
*/
$this->assertEquals( $calced_tax, array( $tax_rate_1_id => 4.3889, $tax_rate_2_id => 7.8341 ) );
$this->assertEquals( round( $calced_tax[ $tax_rate_1_id ], 4 ), 4.3889 );
$this->assertEquals( round( $calced_tax[ $tax_rate_2_id ], 4 ), 7.8341 );
WC_Tax::_delete_tax_rate( $tax_rate_1_id );
WC_Tax::_delete_tax_rate( $tax_rate_2_id );