Merge branch 'master' into feature/screen-option

This commit is contained in:
Shiva Poudel 2018-02-23 09:49:19 +05:45
commit c2c97855be
37 changed files with 772 additions and 613 deletions

View File

@ -6,7 +6,7 @@ When contributing please ensure you follow the guidelines below to help us keep
__Please Note:__ __Please Note:__
GitHub is for _bug reports and contributions only_ - if you have a support question or a request for a customization this is not the right place to post it. Use [WooCommerce Support](https://support.woocommerce.com) for customer support, [WordPress.org](https://wordpress.org/support/plugin/woocommerce) for community support, and for customizations we recommend one of the following services: GitHub is for _bug reports and contributions only_ - if you have a support question or a request for a customization this is not the right place to post it. Use [WooCommerce Support](https://woocommerce.com/contact-us/) for customer support, [WordPress.org](https://wordpress.org/support/plugin/woocommerce) for community support, and for customizations we recommend one of the following services:
- [WooExperts](https://woocommerce.com/experts/) - [WooExperts](https://woocommerce.com/experts/)
- [Codeable](https://codeable.io/) - [Codeable](https://codeable.io/)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -639,6 +639,8 @@ body {
// Toggle display a list of services. // Toggle display a list of services.
.wc-wizard-services-list-toggle { .wc-wizard-services-list-toggle {
cursor: pointer;
.wc-wizard-service-enable::before { .wc-wizard-service-enable::before {
content: "\f343"; // up chevron content: "\f343"; // up chevron
font-family: "dashicons"; font-family: "dashicons";
@ -658,7 +660,6 @@ body {
.wc-wizard-service-enable input { .wc-wizard-service-enable input {
visibility: hidden; visibility: hidden;
position: relative; position: relative;
cursor: pointer;
} }
} }

View File

@ -48,7 +48,7 @@ jQuery( function( $ ) {
$checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).change(); $checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).change();
} ); } );
$( '.wc-wizard-services-list-toggle' ).on( 'change', '.wc-wizard-service-enable input', function() { $( '.wc-wizard-services-list-toggle' ).on( 'click', function() {
$( this ).closest( '.wc-wizard-services-list-toggle' ).toggleClass( 'closed' ); $( this ).closest( '.wc-wizard-services-list-toggle' ).toggleClass( 'closed' );
$( this ).closest( '.wc-wizard-services' ).find( '.wc-wizard-service-item' ) $( this ).closest( '.wc-wizard-services' ).find( '.wc-wizard-service-item' )
.slideToggle() .slideToggle()

View File

@ -1 +1 @@
jQuery(function(e){function i(){e(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}function s(){e("form.activate-jetpack").submit()}function t(){wp.ajax.post("setup_wizard_check_jetpack").then(function(e){if(!e||!e.is_active||"yes"===e.is_active)return s();setTimeout(t,3e3)}).fail(function(){s()})}e(".button-next").on("click",function(){var s=e(this).parents("form").get(0);return("function"!=typeof s.checkValidity||s.checkValidity())&&i(),!0}),e(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-toggle").removeClass("disabled"),e(this).closest(".wc-wizard-service-item").addClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").removeClass("hide")):(e(this).closest(".wc-wizard-service-toggle").addClass("disabled"),e(this).closest(".wc-wizard-service-item").removeClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").addClass("hide"))}),e(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(i){if(e(i.target).is("input"))i.stopPropagation();else{var s=e(this).find('input[type="checkbox"]');s.prop("checked",!s.prop("checked")).change()}}),e(".wc-wizard-services-list-toggle").on("change",".wc-wizard-service-enable input",function(){e(this).closest(".wc-wizard-services-list-toggle").toggleClass("closed"),e(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")}),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-select .method",function(i){var s=e(this).closest(".wc-wizard-service-description"),t=i.target.value,c=s.find(".shipping-method-descriptions");c.find(".shipping-method-description").addClass("hide"),c.find("."+t).removeClass("hide");var r=s.find(".shipping-method-settings");r.find(".shipping-method-setting").addClass("hide").find(".shipping-method-required-field").prop("required",!1),r.find("."+t).removeClass("hide").find(".shipping-method-required-field").prop("required",!0)}).find(".wc-wizard-shipping-method-select .method").change(),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-enable",function(){var i=e(this).is(":checked");e(this).closest(".wc-wizard-service-item").find(".shipping-method-required-field").prop("required",i)}),e(".activate-jetpack").on("click",".button-primary",function(e){if(i(),"no"===wc_setup_params.pending_jetpack_install)return!0;e.preventDefault(),t()}),e(".wc-wizard-services").on("change","input#stripe_create_account, input#ppec_paypal_reroute_requests",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!0),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").show()):(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!1),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").hide())}).find("input#stripe_create_account, input#ppec_paypal_reroute_requests").change(),e("select#store_country_state").on("change",function(){var i=this.value.split(":")[0];e("select#currency_code").val(wc_setup_currencies[i]).change()})}); jQuery(function(e){function i(){e(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}function s(){e("form.activate-jetpack").submit()}function t(){wp.ajax.post("setup_wizard_check_jetpack").then(function(e){if(!e||!e.is_active||"yes"===e.is_active)return s();setTimeout(t,3e3)}).fail(function(){s()})}e(".button-next").on("click",function(){var s=e(this).parents("form").get(0);return("function"!=typeof s.checkValidity||s.checkValidity())&&i(),!0}),e(".wc-wizard-services").on("change",".wc-wizard-service-enable input",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-toggle").removeClass("disabled"),e(this).closest(".wc-wizard-service-item").addClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").removeClass("hide")):(e(this).closest(".wc-wizard-service-toggle").addClass("disabled"),e(this).closest(".wc-wizard-service-item").removeClass("checked"),e(this).closest(".wc-wizard-service-item").find(".wc-wizard-service-settings").addClass("hide"))}),e(".wc-wizard-services").on("click",".wc-wizard-service-enable",function(i){if(e(i.target).is("input"))i.stopPropagation();else{var s=e(this).find('input[type="checkbox"]');s.prop("checked",!s.prop("checked")).change()}}),e(".wc-wizard-services-list-toggle").on("click",function(){e(this).closest(".wc-wizard-services-list-toggle").toggleClass("closed"),e(this).closest(".wc-wizard-services").find(".wc-wizard-service-item").slideToggle().css("display","flex")}),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-select .method",function(i){var s=e(this).closest(".wc-wizard-service-description"),t=i.target.value,c=s.find(".shipping-method-descriptions");c.find(".shipping-method-description").addClass("hide"),c.find("."+t).removeClass("hide");var r=s.find(".shipping-method-settings");r.find(".shipping-method-setting").addClass("hide").find(".shipping-method-required-field").prop("required",!1),r.find("."+t).removeClass("hide").find(".shipping-method-required-field").prop("required",!0)}).find(".wc-wizard-shipping-method-select .method").change(),e(".wc-wizard-services").on("change",".wc-wizard-shipping-method-enable",function(){var i=e(this).is(":checked");e(this).closest(".wc-wizard-service-item").find(".shipping-method-required-field").prop("required",i)}),e(".activate-jetpack").on("click",".button-primary",function(e){if(i(),"no"===wc_setup_params.pending_jetpack_install)return!0;e.preventDefault(),t()}),e(".wc-wizard-services").on("change","input#stripe_create_account, input#ppec_paypal_reroute_requests",function(){e(this).is(":checked")?(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!0),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").show()):(e(this).closest(".wc-wizard-service-settings").find("input.payment-email-input").prop("required",!1),e(this).closest(".wc-wizard-service-settings").find(".wc-wizard-service-setting-stripe_email, .wc-wizard-service-setting-ppec_paypal_email").hide())}).find("input#stripe_create_account, input#ppec_paypal_reroute_requests").change(),e("select#store_country_state").on("change",function(){var i=this.value.split(":")[0];e("select#currency_code").val(wc_setup_currencies[i]).change()})});

View File

@ -1,5 +1,5 @@
/* /*
* jQuery FlexSlider v2.6.1 * jQuery FlexSlider v2.7.0
* Copyright 2012 WooThemes * Copyright 2012 WooThemes
* Contributing Author: Tyler Smith * Contributing Author: Tyler Smith
*/ */
@ -23,7 +23,7 @@
var namespace = slider.vars.namespace, var namespace = slider.vars.namespace,
msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture, msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture,
touch = (( "ontouchstart" in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch) && slider.vars.touch, touch = (( "ontouchstart" in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch) && slider.vars.touch,
// depricating this idea, as devices are being released with both of these events // deprecating this idea, as devices are being released with both of these events
eventType = "click touchend MSPointerUp keyup", eventType = "click touchend MSPointerUp keyup",
watchedEvent = "", watchedEvent = "",
watchedEventClearTimer, watchedEventClearTimer,
@ -792,12 +792,8 @@
} }
} else { // FADE: } else { // FADE:
if (!touch) { if (!touch) {
//slider.slides.eq(slider.currentSlide).fadeOut(slider.vars.animationSpeed, slider.vars.easing);
//slider.slides.eq(target).fadeIn(slider.vars.animationSpeed, slider.vars.easing, slider.wrapup);
slider.slides.eq(slider.currentSlide).css({"zIndex": 1}).animate({"opacity": 0}, slider.vars.animationSpeed, slider.vars.easing); slider.slides.eq(slider.currentSlide).css({"zIndex": 1}).animate({"opacity": 0}, slider.vars.animationSpeed, slider.vars.easing);
slider.slides.eq(target).css({"zIndex": 2}).animate({"opacity": 1}, slider.vars.animationSpeed, slider.vars.easing, slider.wrapup); slider.slides.eq(target).css({"zIndex": 2}).animate({"opacity": 1}, slider.vars.animationSpeed, slider.vars.easing, slider.wrapup);
} else { } else {
slider.slides.eq(slider.currentSlide).css({ "opacity": 0, "zIndex": 1 }); slider.slides.eq(slider.currentSlide).css({ "opacity": 0, "zIndex": 1 });
slider.slides.eq(target).css({ "opacity": 1, "zIndex": 2 }); slider.slides.eq(target).css({ "opacity": 1, "zIndex": 2 });
@ -894,7 +890,7 @@
} }
}()); }());
return (posCalc * -1) + "px"; return (posCalc * ((slider.vars.rtl)?1:-1)) + "px";
}()); }());
if (slider.transitions) { if (slider.transitions) {
@ -954,7 +950,7 @@
setTimeout(function(){ setTimeout(function(){
slider.doMath(); slider.doMath();
if(slider.vars.rtl){ if(slider.vars.rtl){
slider.newSlides.css({"width": slider.computedW, "marginLeft" : slider.computedM, "float": "right", "display": "block"}); slider.newSlides.css({"width": slider.computedW, "marginRight" : slider.computedM, "float": "left", "display": "block"});
} }
else{ else{
slider.newSlides.css({"width": slider.computedW, "marginRight" : slider.computedM, "float": "left", "display": "block"}); slider.newSlides.css({"width": slider.computedW, "marginRight" : slider.computedM, "float": "left", "display": "block"});

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,4 @@
<?php <?php // @codingStandardsIgnoreLine
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
include_once( WC_ABSPATH . 'includes/legacy/abstract-wc-legacy-order.php' );
/** /**
* Abstract Order * Abstract Order
* *
@ -14,8 +8,14 @@ include_once( WC_ABSPATH . 'includes/legacy/abstract-wc-legacy-order.php' );
* @class WC_Abstract_Order * @class WC_Abstract_Order
* @version 3.0.0 * @version 3.0.0
* @package WooCommerce/Classes * @package WooCommerce/Classes
* @category Class */
* @author WooThemes
defined( 'ABSPATH' ) || exit;
require_once WC_ABSPATH . 'includes/legacy/abstract-wc-legacy-order.php';
/**
* WC_Abstract_Order class.
*/ */
abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
@ -65,6 +65,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Stores meta in cache for future reads. * Stores meta in cache for future reads.
* *
* A group must be set to to enable caching. * A group must be set to to enable caching.
*
* @var string * @var string
*/ */
protected $cache_group = 'orders'; protected $cache_group = 'orders';
@ -78,6 +79,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* This is the name of this object type. * This is the name of this object type.
*
* @var string * @var string
*/ */
protected $object_type = 'order'; protected $object_type = 'order';
@ -181,8 +183,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Save all order items which are part of this order. * Save all order items which are part of this order.
*/ */
protected function save_items() { protected function save_items() {
$items_changed = false;
foreach ( $this->items_to_delete as $item ) { foreach ( $this->items_to_delete as $item ) {
$item->delete(); $item->delete();
$items_changed = true;
} }
$this->items_to_delete = array(); $this->items_to_delete = array();
@ -200,10 +205,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$this->items[ $item_group ][ $item_id ] = $item; $this->items[ $item_group ][ $item_id ] = $item;
unset( $this->items[ $item_group ][ $item_key ] ); unset( $this->items[ $item_group ][ $item_key ] );
$items_changed = true;
} }
} }
} }
} }
if ( $items_changed ) {
delete_transient( 'wc_order_' . $this->get_id() . '_needs_processing' );
}
} }
/* /*
@ -216,7 +227,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Get parent order ID. * Get parent order ID.
* *
* @since 3.0.0 * @since 3.0.0
* @param string $context * @param string $context View or edit context.
* @return integer * @return integer
*/ */
public function get_parent_id( $context = 'view' ) { public function get_parent_id( $context = 'view' ) {
@ -226,7 +237,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets order currency. * Gets order currency.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_currency( $context = 'view' ) { public function get_currency( $context = 'view' ) {
@ -236,7 +247,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get order_version. * Get order_version.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_version( $context = 'view' ) { public function get_version( $context = 'view' ) {
@ -246,7 +257,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get prices_include_tax. * Get prices_include_tax.
* *
* @param string $context * @param string $context View or edit context.
* @return bool * @return bool
*/ */
public function get_prices_include_tax( $context = 'view' ) { public function get_prices_include_tax( $context = 'view' ) {
@ -256,7 +267,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get date_created. * Get date_created.
* *
* @param string $context * @param string $context View or edit context.
* @return WC_DateTime|NULL object if the date is set or null if there is no date. * @return WC_DateTime|NULL object if the date is set or null if there is no date.
*/ */
public function get_date_created( $context = 'view' ) { public function get_date_created( $context = 'view' ) {
@ -266,7 +277,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get date_modified. * Get date_modified.
* *
* @param string $context * @param string $context View or edit context.
* @return WC_DateTime|NULL object if the date is set or null if there is no date. * @return WC_DateTime|NULL object if the date is set or null if there is no date.
*/ */
public function get_date_modified( $context = 'view' ) { public function get_date_modified( $context = 'view' ) {
@ -276,7 +287,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Return the order statuses without wc- internal prefix. * Return the order statuses without wc- internal prefix.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_status( $context = 'view' ) { public function get_status( $context = 'view' ) {
@ -292,7 +303,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get discount_total. * Get discount_total.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_discount_total( $context = 'view' ) { public function get_discount_total( $context = 'view' ) {
@ -302,7 +313,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get discount_tax. * Get discount_tax.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_discount_tax( $context = 'view' ) { public function get_discount_tax( $context = 'view' ) {
@ -312,7 +323,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get shipping_total. * Get shipping_total.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_shipping_total( $context = 'view' ) { public function get_shipping_total( $context = 'view' ) {
@ -322,7 +333,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get shipping_tax. * Get shipping_tax.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_shipping_tax( $context = 'view' ) { public function get_shipping_tax( $context = 'view' ) {
@ -332,7 +343,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets cart tax amount. * Gets cart tax amount.
* *
* @param string $context * @param string $context View or edit context.
* @return float * @return float
*/ */
public function get_cart_tax( $context = 'view' ) { public function get_cart_tax( $context = 'view' ) {
@ -342,7 +353,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets order grand total. incl. taxes. Used in gateways. * Gets order grand total. incl. taxes. Used in gateways.
* *
* @param string $context * @param string $context View or edit context.
* @return float * @return float
*/ */
public function get_total( $context = 'view' ) { public function get_total( $context = 'view' ) {
@ -352,7 +363,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get total tax amount. Alias for get_order_tax(). * Get total tax amount. Alias for get_order_tax().
* *
* @param string $context * @param string $context View or edit context.
* @return float * @return float
*/ */
public function get_total_tax( $context = 'view' ) { public function get_total_tax( $context = 'view' ) {
@ -382,6 +393,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets order subtotal. * Gets order subtotal.
*
* @return float * @return float
*/ */
public function get_subtotal() { public function get_subtotal() {
@ -439,7 +451,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get user ID. Used by orders, not other order types like refunds. * Get user ID. Used by orders, not other order types like refunds.
* *
* @param string $context * @param string $context View or edit context.
* @return int * @return int
*/ */
public function get_user_id( $context = 'view' ) { public function get_user_id( $context = 'view' ) {
@ -470,8 +482,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Set parent order ID. * Set parent order ID.
* *
* @since 3.0.0 * @since 3.0.0
* @param int $value * @param int $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception thrown if parent ID does not exist or is invalid.
*/ */
public function set_parent_id( $value ) { public function set_parent_id( $value ) {
if ( $value && ( $value === $this->get_id() || ! wc_get_order( $value ) ) ) { if ( $value && ( $value === $this->get_id() || ! wc_get_order( $value ) ) ) {
@ -493,13 +505,13 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
// If setting the status, ensure it's set to a valid status. // If setting the status, ensure it's set to a valid status.
if ( true === $this->object_read ) { if ( true === $this->object_read ) {
// Only allow valid new status // Only allow valid new status.
if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) && 'trash' !== $new_status ) { if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses(), true ) && 'trash' !== $new_status ) {
$new_status = 'pending'; $new_status = 'pending';
} }
// If the old status is set but unknown (e.g. draft) assume its pending for action usage. // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses() ) && 'trash' !== $old_status ) { if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses(), true ) && 'trash' !== $old_status ) {
$old_status = 'pending'; $old_status = 'pending';
} }
} }
@ -515,8 +527,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set order_version. * Set order_version.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_version( $value ) { public function set_version( $value ) {
$this->set_prop( 'version', $value ); $this->set_prop( 'version', $value );
@ -525,11 +537,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set order_currency. * Set order_currency.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_currency( $value ) { public function set_currency( $value ) {
if ( $value && ! in_array( $value, array_keys( get_woocommerce_currencies() ) ) ) { if ( $value && ! in_array( $value, array_keys( get_woocommerce_currencies() ), true ) ) {
$this->error( 'order_invalid_currency', __( 'Invalid currency code', 'woocommerce' ) ); $this->error( 'order_invalid_currency', __( 'Invalid currency code', 'woocommerce' ) );
} }
$this->set_prop( 'currency', $value ? $value : get_woocommerce_currency() ); $this->set_prop( 'currency', $value ? $value : get_woocommerce_currency() );
@ -538,8 +550,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set prices_include_tax. * Set prices_include_tax.
* *
* @param bool $value * @param bool $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_prices_include_tax( $value ) { public function set_prices_include_tax( $value ) {
$this->set_prop( 'prices_include_tax', (bool) $value ); $this->set_prop( 'prices_include_tax', (bool) $value );
@ -549,7 +561,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Set date_created. * Set date_created.
* *
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_date_created( $date = null ) { public function set_date_created( $date = null ) {
$this->set_date_prop( 'date_created', $date ); $this->set_date_prop( 'date_created', $date );
@ -559,7 +571,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Set date_modified. * Set date_modified.
* *
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date. * @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_date_modified( $date = null ) { public function set_date_modified( $date = null ) {
$this->set_date_prop( 'date_modified', $date ); $this->set_date_prop( 'date_modified', $date );
@ -568,8 +580,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set discount_total. * Set discount_total.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_discount_total( $value ) { public function set_discount_total( $value ) {
$this->set_prop( 'discount_total', wc_format_decimal( $value ) ); $this->set_prop( 'discount_total', wc_format_decimal( $value ) );
@ -578,8 +590,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set discount_tax. * Set discount_tax.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_discount_tax( $value ) { public function set_discount_tax( $value ) {
$this->set_prop( 'discount_tax', wc_format_decimal( $value ) ); $this->set_prop( 'discount_tax', wc_format_decimal( $value ) );
@ -588,8 +600,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set shipping_total. * Set shipping_total.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_shipping_total( $value ) { public function set_shipping_total( $value ) {
$this->set_prop( 'shipping_total', wc_format_decimal( $value ) ); $this->set_prop( 'shipping_total', wc_format_decimal( $value ) );
@ -598,8 +610,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set shipping_tax. * Set shipping_tax.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_shipping_tax( $value ) { public function set_shipping_tax( $value ) {
$this->set_prop( 'shipping_tax', wc_format_decimal( $value ) ); $this->set_prop( 'shipping_tax', wc_format_decimal( $value ) );
@ -609,8 +621,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set cart tax. * Set cart tax.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_cart_tax( $value ) { public function set_cart_tax( $value ) {
$this->set_prop( 'cart_tax', wc_format_decimal( $value ) ); $this->set_prop( 'cart_tax', wc_format_decimal( $value ) );
@ -620,8 +632,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Sets order tax (sum of cart and shipping tax). Used internally only. * Sets order tax (sum of cart and shipping tax). Used internally only.
* *
* @param string $value * @param string $value Value to set.
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
protected function set_total_tax( $value ) { protected function set_total_tax( $value ) {
$this->set_prop( 'total_tax', wc_format_decimal( $value ) ); $this->set_prop( 'total_tax', wc_format_decimal( $value ) );
@ -630,11 +642,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Set total. * Set total.
* *
* @param string $value * @param string $value Value to set.
* @param string $deprecated Function used to set different totals based on this. * @param string $deprecated Function used to set different totals based on this.
* *
* @return bool|void * @return bool|void
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception may be thrown if value is invalid.
*/ */
public function set_total( $value, $deprecated = '' ) { public function set_total( $value, $deprecated = '' ) {
if ( $deprecated ) { if ( $deprecated ) {
@ -662,7 +674,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
if ( ! empty( $type ) ) { if ( ! empty( $type ) ) {
$this->data_store->delete_items( $this, $type ); $this->data_store->delete_items( $this, $type );
if ( $group = $this->type_to_group( $type ) ) { $group = $this->type_to_group( $type );
if ( $group ) {
unset( $this->items[ $group ] ); unset( $this->items[ $group ] );
} }
} else { } else {
@ -674,8 +688,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Convert a type to a types group. * Convert a type to a types group.
* *
* @param string $type * @param string $type type to lookup.
* @return string group * @return string
*/ */
protected function type_to_group( $type ) { protected function type_to_group( $type ) {
$type_to_group = apply_filters( 'woocommerce_order_type_to_group', array( $type_to_group = apply_filters( 'woocommerce_order_type_to_group', array(
@ -699,11 +713,13 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$types = array_filter( (array) $types ); $types = array_filter( (array) $types );
foreach ( $types as $type ) { foreach ( $types as $type ) {
if ( $group = $this->type_to_group( $type ) ) { $group = $this->type_to_group( $type );
if ( $group ) {
if ( ! isset( $this->items[ $group ] ) ) { if ( ! isset( $this->items[ $group ] ) ) {
$this->items[ $group ] = array_filter( $this->data_store->read_items( $this, $type ) ); $this->items[ $group ] = array_filter( $this->data_store->read_items( $this, $type ) );
} }
// Don't use array_merge here because keys are numeric // Don't use array_merge here because keys are numeric.
$items = $items + $this->items[ $group ]; $items = $items + $this->items[ $group ];
} }
} }
@ -758,7 +774,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
*/ */
public function get_used_coupons() { public function get_used_coupons() {
$coupon_codes = array(); $coupon_codes = array();
if ( $coupons = $this->get_items( 'coupon' ) ) { $coupons = $this->get_items( 'coupon' );
if ( $coupons ) {
foreach ( $coupons as $coupon ) { foreach ( $coupons as $coupon ) {
$coupon_codes[] = $coupon->get_code(); $coupon_codes[] = $coupon->get_code();
} }
@ -769,7 +787,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets the count of order items of a certain type. * Gets the count of order items of a certain type.
* *
* @param string $item_type * @param string $item_type Item type to lookup.
* @return string * @return string
*/ */
public function get_item_count( $item_type = '' ) { public function get_item_count( $item_type = '' ) {
@ -821,7 +839,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Get key for where a certain item type is stored in _items. * Get key for where a certain item type is stored in _items.
* *
* @since 3.0.0 * @since 3.0.0
* @param $item object Order item (product, shipping, fee, coupon, tax) * @param string $item object Order item (product, shipping, fee, coupon, tax).
* @return string * @return string
*/ */
protected function get_items_key( $item ) { protected function get_items_key( $item ) {
@ -847,8 +865,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
*/ */
public function remove_item( $item_id ) { public function remove_item( $item_id ) {
$item = $this->get_item( $item_id, false ); $item = $this->get_item( $item_id, false );
$items_key = $item ? $this->get_items_key( $item ) : false;
if ( ! $item || ! ( $items_key = $this->get_items_key( $item ) ) ) { if ( ! $items_key ) {
return false; return false;
} }
@ -861,12 +880,13 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Adds an order item to this order. The order item will not persist until save. * Adds an order item to this order. The order item will not persist until save.
* *
* @since 3.0.0 * @since 3.0.0
* @param WC_Order_Item Order item object (product, shipping, fee, coupon, tax) * @param WC_Order_Item $item Order item object (product, shipping, fee, coupon, tax).
*
* @return false|void * @return false|void
*/ */
public function add_item( $item ) { public function add_item( $item ) {
if ( ! $items_key = $this->get_items_key( $item ) ) { $items_key = $this->get_items_key( $item );
if ( ! $items_key ) {
return false; return false;
} }
@ -879,10 +899,12 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$item->set_order_id( $this->get_id() ); $item->set_order_id( $this->get_id() );
// Append new row with generated temporary ID. // Append new row with generated temporary ID.
if ( $item_id = $item->get_id() ) { $item_id = $item->get_id();
if ( $item_id ) {
$this->items[ $items_key ][ $item_id ] = $item; $this->items[ $items_key ][ $item_id ] = $item;
} else { } else {
$this->items[ $items_key ][ 'new:' . $items_key . sizeof( $this->items[ $items_key ] ) ] = $item; $this->items[ $items_key ][ 'new:' . $items_key . count( $this->items[ $items_key ] ) ] = $item;
} }
} }
@ -936,7 +958,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$this->calculate_totals( true ); $this->calculate_totals( true );
// Record usage so counts and validation is correct. // Record usage so counts and validation is correct.
if ( ! $used_by = $this->get_user_id() ) { $used_by = $this->get_user_id();
if ( ! $used_by ) {
$used_by = $this->get_billing_email(); $used_by = $this->get_billing_email();
} }
@ -1044,7 +1068,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* @param WC_Discounts $discounts Discounts class. * @param WC_Discounts $discounts Discounts class.
*/ */
protected function set_item_discount_amounts( $discounts ) { protected function set_item_discount_amounts( $discounts ) {
if ( $item_discounts = $discounts->get_discounts_by_item() ) { $item_discounts = $discounts->get_discounts_by_item();
if ( $item_discounts ) {
foreach ( $item_discounts as $item_id => $amount ) { foreach ( $item_discounts as $item_id => $amount ) {
$item = $this->get_item( $item_id, false ); $item = $this->get_item( $item_id, false );
@ -1110,11 +1136,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Add a product line item to the order. This is the only line item type with * Add a product line item to the order. This is the only line item type with
* it's own method because it saves looking up order amounts (costs are added up for you). * it's own method because it saves looking up order amounts (costs are added up for you).
* *
* @param \WC_Product $product * @param WC_Product $product Product object.
* @param int $qty * @param int $qty Quantity to add.
* @param array $args * @param array $args Args for the added product.
* @return int order item ID * @return int
* @throws WC_Data_Exception * @throws WC_Data_Exception Exception thrown if the item cannot be added to the cart.
*/ */
public function add_product( $product, $qty = 1, $args = array() ) { public function add_product( $product, $qty = 1, $args = array() ) {
if ( $product ) { if ( $product ) {
@ -1136,7 +1162,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$args = wp_parse_args( $args, $default_args ); $args = wp_parse_args( $args, $default_args );
// BW compatibility with old args // BW compatibility with old args.
if ( isset( $args['totals'] ) ) { if ( isset( $args['totals'] ) ) {
foreach ( $args['totals'] as $key => $value ) { foreach ( $args['totals'] as $key => $value ) {
if ( 'tax' === $key ) { if ( 'tax' === $key ) {
@ -1172,7 +1198,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Add a payment token to an order * Add a payment token to an order
* *
* @since 2.6 * @since 2.6
* @param WC_Payment_Token $token Payment token object * @param WC_Payment_Token $token Payment token object.
* @return boolean|int The new token ID or false if it failed. * @return boolean|int The new token ID or false if it failed.
*/ */
public function add_payment_token( $token ) { public function add_payment_token( $token ) {
@ -1248,7 +1274,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
* Get tax location for this order. * Get tax location for this order.
* *
* @since 3.2.0 * @since 3.2.0
* @param $args array Override the location. * @param array $args array Override the location.
* @return array * @return array
*/ */
protected function get_tax_location( $args = array() ) { protected function get_tax_location( $args = array() ) {
@ -1265,7 +1291,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
'city' => 'billing' === $tax_based_on ? $this->get_billing_city() : $this->get_shipping_city(), 'city' => 'billing' === $tax_based_on ? $this->get_billing_city() : $this->get_shipping_city(),
) ); ) );
// Default to base // Default to base.
if ( 'base' === $tax_based_on || empty( $args['country'] ) ) { if ( 'base' === $tax_based_on || empty( $args['country'] ) ) {
$default = wc_get_base_location(); $default = wc_get_base_location();
$args['country'] = $default['country']; $args['country'] = $default['country'];
@ -1294,8 +1320,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' ); $shipping_tax_class = get_option( 'woocommerce_shipping_tax_class' );
if ( 'inherit' === $shipping_tax_class ) { if ( 'inherit' === $shipping_tax_class ) {
$found_classes = array_intersect( array_merge( array( '' ), WC_Tax :: get_tax_class_slugs() ), $this->get_items_tax_classes() ); $found_classes = array_intersect( array_merge( array( '' ), WC_Tax::get_tax_class_slugs() ), $this->get_items_tax_classes() );
$shipping_tax_class = count( $found_classes ) ? current( $found_classes ): false; $shipping_tax_class = count( $found_classes ) ? current( $found_classes ) : false;
} }
$is_vat_exempt = apply_filters( 'woocommerce_order_is_vat_exempt', 'yes' === $this->get_meta( 'is_vat_exempt' ) ); $is_vat_exempt = apply_filters( 'woocommerce_order_is_vat_exempt', 'yes' === $this->get_meta( 'is_vat_exempt' ) );
@ -1345,7 +1371,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
foreach ( $existing_taxes as $tax ) { foreach ( $existing_taxes as $tax ) {
// Remove taxes which no longer exist for cart/shipping. // Remove taxes which no longer exist for cart/shipping.
if ( ( ! array_key_exists( $tax->get_rate_id(), $cart_taxes ) && ! array_key_exists( $tax->get_rate_id(), $shipping_taxes ) ) || in_array( $tax->get_rate_id(), $saved_rate_ids ) ) { if ( ( ! array_key_exists( $tax->get_rate_id(), $cart_taxes ) && ! array_key_exists( $tax->get_rate_id(), $shipping_taxes ) ) || in_array( $tax->get_rate_id(), $saved_rate_ids, true ) ) {
$this->remove_item( $tax->get_id() ); $this->remove_item( $tax->get_id() );
continue; continue;
} }
@ -1448,7 +1474,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get item subtotal - this is the cost before discount. * Get item subtotal - this is the cost before discount.
* *
* @param object $item * @param object $item Item to get total from.
* @param bool $inc_tax (default: false). * @param bool $inc_tax (default: false).
* @param bool $round (default: true). * @param bool $round (default: true).
* @return float * @return float
@ -1472,7 +1498,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get line subtotal - this is the cost before discount. * Get line subtotal - this is the cost before discount.
* *
* @param object $item * @param object $item Item to get total from.
* @param bool $inc_tax (default: false). * @param bool $inc_tax (default: false).
* @param bool $round (default: true). * @param bool $round (default: true).
* @return float * @return float
@ -1496,7 +1522,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Calculate item cost - useful for gateways. * Calculate item cost - useful for gateways.
* *
* @param object $item * @param object $item Item to get total from.
* @param bool $inc_tax (default: false). * @param bool $inc_tax (default: false).
* @param bool $round (default: true). * @param bool $round (default: true).
* @return float * @return float
@ -1520,7 +1546,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Calculate line total - useful for gateways. * Calculate line total - useful for gateways.
* *
* @param object $item * @param object $item Item to get total from.
* @param bool $inc_tax (default: false). * @param bool $inc_tax (default: false).
* @param bool $round (default: true). * @param bool $round (default: true).
* @return float * @return float
@ -1542,7 +1568,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get item tax - useful for gateways. * Get item tax - useful for gateways.
* *
* @param mixed $item * @param mixed $item Item to get total from.
* @param bool $round (default: true). * @param bool $round (default: true).
* @return float * @return float
*/ */
@ -1560,7 +1586,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get line tax - useful for gateways. * Get line tax - useful for gateways.
* *
* @param mixed $item * @param mixed $item Item to get total from.
* @return float * @return float
*/ */
public function get_line_tax( $item ) { public function get_line_tax( $item ) {
@ -1570,17 +1596,20 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets line subtotal - formatted for display. * Gets line subtotal - formatted for display.
* *
* @param array $item * @param array $item Item to get total from.
* @param string $tax_display * @param string $tax_display Incl or excl tax display mode.
* @return string * @return string
*/ */
public function get_formatted_line_subtotal( $item, $tax_display = '' ) { public function get_formatted_line_subtotal( $item, $tax_display = '' ) {
$tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' ); $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
if ( 'excl' == $tax_display ) { if ( 'excl' === $tax_display ) {
$ex_tax_label = $this->get_prices_include_tax() ? 1 : 0; $ex_tax_label = $this->get_prices_include_tax() ? 1 : 0;
$subtotal = wc_price( $this->get_line_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label, 'currency' => $this->get_currency() ) ); $subtotal = wc_price( $this->get_line_subtotal( $item ), array(
'ex_tax_label' => $ex_tax_label,
'currency' => $this->get_currency(),
) );
} else { } else {
$subtotal = wc_price( $this->get_line_subtotal( $item, true ), array( 'currency' => $this->get_currency() ) ); $subtotal = wc_price( $this->get_line_subtotal( $item, true ), array( 'currency' => $this->get_currency() ) );
} }
@ -1590,6 +1619,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets order total - formatted for display. * Gets order total - formatted for display.
*
* @return string * @return string
*/ */
public function get_formatted_order_total() { public function get_formatted_order_total() {
@ -1653,21 +1683,20 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Gets shipping (formatted). * Gets shipping (formatted).
* *
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*
* @return string * @return string
*/ */
public function get_shipping_to_display( $tax_display = '' ) { public function get_shipping_to_display( $tax_display = '' ) {
$tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' ); $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
if ( $this->get_shipping_total() != 0 ) { if ( $this->get_shipping_total() !== 0 ) {
if ( 'excl' === $tax_display ) { if ( 'excl' === $tax_display ) {
// Show shipping excluding tax. // Show shipping excluding tax.
$shipping = wc_price( $this->get_shipping_total(), array( 'currency' => $this->get_currency() ) ); $shipping = wc_price( $this->get_shipping_total(), array( 'currency' => $this->get_currency() ) );
if ( $this->get_shipping_tax() != 0 && $this->get_prices_include_tax() ) { if ( $this->get_shipping_tax() !== 0 && $this->get_prices_include_tax() ) {
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', '&nbsp;<small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>', $this, $tax_display ); $shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', '&nbsp;<small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>', $this, $tax_display );
} }
} else { } else {
@ -1675,7 +1704,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
// Show shipping including tax. // Show shipping including tax.
$shipping = wc_price( $this->get_shipping_total() + $this->get_shipping_tax(), array( 'currency' => $this->get_currency() ) ); $shipping = wc_price( $this->get_shipping_total() + $this->get_shipping_tax(), array( 'currency' => $this->get_currency() ) );
if ( $this->get_shipping_tax() != 0 && ! $this->get_prices_include_tax() ) { if ( $this->get_shipping_tax() !== 0 && ! $this->get_prices_include_tax() ) {
$shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', '&nbsp;<small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>', $this, $tax_display ); $shipping .= apply_filters( 'woocommerce_order_shipping_to_display_tax_label', '&nbsp;<small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>', $this, $tax_display );
} }
} }
@ -1694,10 +1723,9 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get the discount amount (formatted). * Get the discount amount (formatted).
*
* @since 2.3.0 * @since 2.3.0
* * @param string $tax_display Excl or incl tax display mode.
* @param string $tax_display
*
* @return string * @return string
*/ */
public function get_discount_to_display( $tax_display = '' ) { public function get_discount_to_display( $tax_display = '' ) {
@ -1708,11 +1736,13 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Add total row for subtotal. * Add total row for subtotal.
* *
* @param array $total_rows * @param array $total_rows Reference to total rows array.
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*/ */
protected function add_order_item_totals_subtotal_row( &$total_rows, $tax_display ) { protected function add_order_item_totals_subtotal_row( &$total_rows, $tax_display ) {
if ( $subtotal = $this->get_subtotal_to_display( false, $tax_display ) ) { $subtotal = $this->get_subtotal_to_display( false, $tax_display );
if ( $subtotal ) {
$total_rows['cart_subtotal'] = array( $total_rows['cart_subtotal'] = array(
'label' => __( 'Subtotal:', 'woocommerce' ), 'label' => __( 'Subtotal:', 'woocommerce' ),
'value' => $subtotal, 'value' => $subtotal,
@ -1723,8 +1753,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Add total row for discounts. * Add total row for discounts.
* *
* @param array $total_rows * @param array $total_rows Reference to total rows array.
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*/ */
protected function add_order_item_totals_discount_row( &$total_rows, $tax_display ) { protected function add_order_item_totals_discount_row( &$total_rows, $tax_display ) {
if ( $this->get_total_discount() > 0 ) { if ( $this->get_total_discount() > 0 ) {
@ -1738,8 +1768,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Add total row for shipping. * Add total row for shipping.
* *
* @param array $total_rows * @param array $total_rows Reference to total rows array.
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*/ */
protected function add_order_item_totals_shipping_row( &$total_rows, $tax_display ) { protected function add_order_item_totals_shipping_row( &$total_rows, $tax_display ) {
if ( $this->get_shipping_method() ) { if ( $this->get_shipping_method() ) {
@ -1753,11 +1783,13 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Add total row for fees. * Add total row for fees.
* *
* @param array $total_rows * @param array $total_rows Reference to total rows array.
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*/ */
protected function add_order_item_totals_fee_rows( &$total_rows, $tax_display ) { protected function add_order_item_totals_fee_rows( &$total_rows, $tax_display ) {
if ( $fees = $this->get_fees() ) { $fees = $this->get_fees();
if ( $fees ) {
foreach ( $fees as $id => $fee ) { foreach ( $fees as $id => $fee ) {
if ( apply_filters( 'woocommerce_get_order_item_totals_excl_free_fees', empty( $fee['line_total'] ) && empty( $fee['line_tax'] ), $id ) ) { if ( apply_filters( 'woocommerce_get_order_item_totals_excl_free_fees', empty( $fee['line_total'] ) && empty( $fee['line_tax'] ), $id ) ) {
continue; continue;
@ -1773,8 +1805,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Add total row for taxes. * Add total row for taxes.
* *
* @param array $total_rows * @param array $total_rows Reference to total rows array.
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*/ */
protected function add_order_item_totals_tax_rows( &$total_rows, $tax_display ) { protected function add_order_item_totals_tax_rows( &$total_rows, $tax_display ) {
// Tax for tax exclusive prices. // Tax for tax exclusive prices.
@ -1798,8 +1830,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Add total row for grand total. * Add total row for grand total.
* *
* @param array $total_rows * @param array $total_rows Reference to total rows array.
* @param string $tax_display * @param string $tax_display Excl or incl tax display mode.
*/ */
protected function add_order_item_totals_total_row( &$total_rows, $tax_display ) { protected function add_order_item_totals_total_row( &$total_rows, $tax_display ) {
$total_rows['order_total'] = array( $total_rows['order_total'] = array(
@ -1811,7 +1843,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Get totals for display on pages and in emails. * Get totals for display on pages and in emails.
* *
* @param mixed $tax_display * @param mixed $tax_display Excl or incl tax display mode.
* @return array * @return array
*/ */
public function get_order_item_totals( $tax_display = '' ) { public function get_order_item_totals( $tax_display = '' ) {
@ -1840,18 +1872,17 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Checks the order status against a passed in status. * Checks the order status against a passed in status.
* *
* @param array|string $status * @param array|string $status Status to check.
*
* @return bool * @return bool
*/ */
public function has_status( $status ) { public function has_status( $status ) {
return apply_filters( 'woocommerce_order_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); return apply_filters( 'woocommerce_order_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status ? true : false, $this, $status );
} }
/** /**
* Check whether this order has a specific shipping method or not. * Check whether this order has a specific shipping method or not.
* *
* @param string $method_id * @param string $method_id Method ID to check.
* @return bool * @return bool
*/ */
public function has_shipping_method( $method_id ) { public function has_shipping_method( $method_id ) {
@ -1865,6 +1896,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/** /**
* Returns true if the order contains a free product. * Returns true if the order contains a free product.
*
* @since 2.5.0 * @since 2.5.0
* @return bool * @return bool
*/ */

View File

@ -1,60 +1,64 @@
<?php <?php // @codingStandardsIgnoreLine.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Abstract Settings API Class * Abstract Settings API Class
* *
* Admin Settings API used by Integrations, Shipping Methods, and Payment Gateways. * Admin Settings API used by Integrations, Shipping Methods, and Payment Gateways.
* *
* @class WC_Settings_API
* @version 2.6.0
* @package WooCommerce/Abstracts * @package WooCommerce/Abstracts
* @category Abstract Class */
* @author WooThemes
defined( 'ABSPATH' ) || exit;
/**
* WC_Settings_API class.
*/ */
abstract class WC_Settings_API { abstract class WC_Settings_API {
/** /**
* The plugin ID. Used for option names. * The plugin ID. Used for option names.
*
* @var string * @var string
*/ */
public $plugin_id = 'woocommerce_'; public $plugin_id = 'woocommerce_';
/** /**
* ID of the class extending the settings API. Used in option names. * ID of the class extending the settings API. Used in option names.
*
* @var string * @var string
*/ */
public $id = ''; public $id = '';
/** /**
* Validation errors. * Validation errors.
*
* @var array of strings * @var array of strings
*/ */
public $errors = array(); public $errors = array();
/** /**
* Setting values. * Setting values.
*
* @var array * @var array
*/ */
public $settings = array(); public $settings = array();
/** /**
* Form option fields. * Form option fields.
*
* @var array * @var array
*/ */
public $form_fields = array(); public $form_fields = array();
/** /**
* The posted settings data. When empty, $_POST data will be used. * The posted settings data. When empty, $_POST data will be used.
*
* @var array * @var array
*/ */
protected $data = array(); protected $data = array();
/** /**
* Get the form fields after they are initialized. * Get the form fields after they are initialized.
*
* @return array of options * @return array of options
*/ */
public function get_form_fields() { public function get_form_fields() {
@ -64,8 +68,7 @@ abstract class WC_Settings_API {
/** /**
* Set default required properties for each field. * Set default required properties for each field.
* *
* @param array $field * @param array $field Setting field array.
*
* @return array * @return array
*/ */
protected function set_defaults( $field ) { protected function set_defaults( $field ) {
@ -79,14 +82,13 @@ abstract class WC_Settings_API {
* Output the admin options table. * Output the admin options table.
*/ */
public function admin_options() { public function admin_options() {
echo '<table class="form-table">' . $this->generate_settings_html( $this->get_form_fields(), false ) . '</table>'; echo '<table class="form-table">' . $this->generate_settings_html( $this->get_form_fields(), false ) . '</table>'; // WPCS: XSS ok.
} }
/** /**
* Initialise settings form fields. * Initialise settings form fields.
* *
* Add an array of fields to be displayed * Add an array of fields to be displayed on the gateway's settings screen.
* on the gateway's settings screen.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -94,6 +96,7 @@ abstract class WC_Settings_API {
/** /**
* Return the name of the option in the WP DB. * Return the name of the option in the WP DB.
*
* @since 2.6.0 * @since 2.6.0
* @return string * @return string
*/ */
@ -103,7 +106,8 @@ abstract class WC_Settings_API {
/** /**
* Get a fields type. Defaults to "text" if not set. * Get a fields type. Defaults to "text" if not set.
* @param array $field *
* @param array $field Field key.
* @return string * @return string
*/ */
public function get_field_type( $field ) { public function get_field_type( $field ) {
@ -112,7 +116,8 @@ abstract class WC_Settings_API {
/** /**
* Get a fields default value. Defaults to "" if not set. * Get a fields default value. Defaults to "" if not set.
* @param array $field *
* @param array $field Field key.
* @return string * @return string
*/ */
public function get_field_default( $field ) { public function get_field_default( $field ) {
@ -121,35 +126,40 @@ abstract class WC_Settings_API {
/** /**
* Get a field's posted and validated value. * Get a field's posted and validated value.
* @param string $key *
* @param array $field * @param string $key Field key.
* @param array $post_data * @param array $field Field array.
* @param array $post_data Posted data.
* @return string * @return string
*/ */
public function get_field_value( $key, $field, $post_data = array() ) { public function get_field_value( $key, $field, $post_data = array() ) {
$type = $this->get_field_type( $field ); $type = $this->get_field_type( $field );
$field_key = $this->get_field_key( $key ); $field_key = $this->get_field_key( $key );
$post_data = empty( $post_data ) ? $_POST : $post_data; $post_data = empty( $post_data ) ? $_POST : $post_data; // WPCS: CSRF ok, input var ok.
$value = isset( $post_data[ $field_key ] ) ? $post_data[ $field_key ] : null; $value = isset( $post_data[ $field_key ] ) ? $post_data[ $field_key ] : null;
// Look for a validate_FIELDID_field method for special handling if ( isset( $field['sanitize_callback'] ) && is_callable( $field['sanitize_callback'] ) ) {
return call_user_func( $field['sanitize_callback'], $value );
}
// Look for a validate_FIELDID_field method for special handling.
if ( is_callable( array( $this, 'validate_' . $key . '_field' ) ) ) { if ( is_callable( array( $this, 'validate_' . $key . '_field' ) ) ) {
return $this->{'validate_' . $key . '_field'}( $key, $value ); return $this->{'validate_' . $key . '_field'}( $key, $value );
} }
// Look for a validate_FIELDTYPE_field method // Look for a validate_FIELDTYPE_field method.
if ( is_callable( array( $this, 'validate_' . $type . '_field' ) ) ) { if ( is_callable( array( $this, 'validate_' . $type . '_field' ) ) ) {
return $this->{'validate_' . $type . '_field'}( $key, $value ); return $this->{'validate_' . $type . '_field'}( $key, $value );
} }
// Fallback to text // Fallback to text.
return $this->validate_text_field( $key, $value ); return $this->validate_text_field( $key, $value );
} }
/** /**
* Sets the POSTed data. This method can be used to set specific data, instead * Sets the POSTed data. This method can be used to set specific data, instead of taking it from the $_POST array.
* of taking it from the $_POST array. *
* @param array data * @param array $data Posted data.
*/ */
public function set_post_data( $data = array() ) { public function set_post_data( $data = array() ) {
$this->data = $data; $this->data = $data;
@ -157,18 +167,20 @@ abstract class WC_Settings_API {
/** /**
* Returns the POSTed data, to be used to save the settings. * Returns the POSTed data, to be used to save the settings.
*
* @return array * @return array
*/ */
public function get_post_data() { public function get_post_data() {
if ( ! empty( $this->data ) && is_array( $this->data ) ) { if ( ! empty( $this->data ) && is_array( $this->data ) ) {
return $this->data; return $this->data;
} }
return $_POST; return $_POST; // WPCS: CSRF ok, input var ok.
} }
/** /**
* Processes and saves options. * Processes and saves options.
* If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out. * If there is an error thrown, will continue to save and validate fields, but will leave the erroring field out.
*
* @return bool was anything saved? * @return bool was anything saved?
*/ */
public function process_admin_options() { public function process_admin_options() {
@ -191,7 +203,8 @@ abstract class WC_Settings_API {
/** /**
* Add an error message for display in admin on save. * Add an error message for display in admin on save.
* @param string $error *
* @param string $error Error message.
*/ */
public function add_error( $error ) { public function add_error( $error ) {
$this->errors[] = $error; $this->errors[] = $error;
@ -238,12 +251,12 @@ abstract class WC_Settings_API {
} }
/** /**
* get_option function. * Get option from DB.
* *
* Gets an option from the settings API, using defaults if necessary to prevent undefined notices. * Gets an option from the settings API, using defaults if necessary to prevent undefined notices.
* *
* @param string $key * @param string $key Option key.
* @param mixed $empty_value * @param mixed $empty_value Value when empty.
* @return string The value specified for the option or a default value for the option. * @return string The value specified for the option or a default value for the option.
*/ */
public function get_option( $key, $empty_value = null ) { public function get_option( $key, $empty_value = null ) {
@ -267,7 +280,7 @@ abstract class WC_Settings_API {
/** /**
* Prefix key for settings. * Prefix key for settings.
* *
* @param mixed $key * @param string $key Field key.
* @return string * @return string
*/ */
public function get_field_key( $key ) { public function get_field_key( $key ) {
@ -279,9 +292,8 @@ abstract class WC_Settings_API {
* *
* Generate the HTML for the fields on the "settings" screen. * Generate the HTML for the fields on the "settings" screen.
* *
* @param array $form_fields (default: array()) * @param array $form_fields (default: array()) Array of form fields.
* @param bool $echo * @param bool $echo Echo or return.
*
* @return string the html for the settings * @return string the html for the settings
* @since 1.0.0 * @since 1.0.0
* @uses method_exists() * @uses method_exists()
@ -303,7 +315,7 @@ abstract class WC_Settings_API {
} }
if ( $echo ) { if ( $echo ) {
echo $html; echo $html; // WPCS: XSS ok.
} else { } else {
return $html; return $html;
} }
@ -312,7 +324,7 @@ abstract class WC_Settings_API {
/** /**
* Get HTML for tooltips. * Get HTML for tooltips.
* *
* @param array $data * @param array $data Data for the tooltip.
* @return string * @return string
*/ */
public function get_tooltip_html( $data ) { public function get_tooltip_html( $data ) {
@ -330,7 +342,7 @@ abstract class WC_Settings_API {
/** /**
* Get HTML for descriptions. * Get HTML for descriptions.
* *
* @param array $data * @param array $data Data for the description.
* @return string * @return string
*/ */
public function get_description_html( $data ) { public function get_description_html( $data ) {
@ -350,7 +362,7 @@ abstract class WC_Settings_API {
/** /**
* Get custom attributes. * Get custom attributes.
* *
* @param array $data * @param array $data Field data.
* @return string * @return string
*/ */
public function get_custom_attribute_html( $data ) { public function get_custom_attribute_html( $data ) {
@ -368,8 +380,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Text Input HTML. * Generate Text Input HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -393,14 +405,14 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> />
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -412,8 +424,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Price Input HTML. * Generate Price Input HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -437,14 +449,14 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> />
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -456,8 +468,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Decimal Input HTML. * Generate Decimal Input HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -481,14 +493,14 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_decimal( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_decimal( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> />
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -500,8 +512,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Password Input HTML. * Generate Password Input HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -513,8 +525,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Color Picker Input HTML. * Generate Color Picker Input HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -537,16 +549,16 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<span class="colorpickpreview" style="background:<?php echo esc_attr( $this->get_option( $key ) ); ?>;"></span> <span class="colorpickpreview" style="background:<?php echo esc_attr( $this->get_option( $key ) ); ?>;"></span>
<input class="colorpick <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <input class="colorpick <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> />
<div id="colorPickerDiv_<?php echo esc_attr( $field_key ); ?>" class="colorpickdiv" style="z-index: 100; background: #eee; border: 1px solid #ccc; position: absolute; display: none;"></div> <div id="colorPickerDiv_<?php echo esc_attr( $field_key ); ?>" class="colorpickdiv" style="z-index: 100; background: #eee; border: 1px solid #ccc; position: absolute; display: none;"></div>
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -558,8 +570,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Textarea HTML. * Generate Textarea HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -583,14 +595,14 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<textarea rows="3" cols="20" class="input-text wide-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo esc_textarea( $this->get_option( $key ) ); ?></textarea> <textarea rows="3" cols="20" class="input-text wide-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>><?php echo esc_textarea( $this->get_option( $key ) ); ?></textarea>
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -602,8 +614,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Checkbox HTML. * Generate Checkbox HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -631,15 +643,15 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<label for="<?php echo esc_attr( $field_key ); ?>"> <label for="<?php echo esc_attr( $field_key ); ?>">
<input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="1" <?php checked( $this->get_option( $key ), 'yes' ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <?php echo wp_kses_post( $data['label'] ); ?></label><br/> <input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="1" <?php checked( $this->get_option( $key ), 'yes' ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?> /> <?php echo wp_kses_post( $data['label'] ); ?></label><br/>
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -651,8 +663,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Select HTML. * Generate Select HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -677,18 +689,18 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>> <select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>>
<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?> <?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, esc_attr( $this->get_option( $key ) ) ); ?>><?php echo esc_attr( $option_value ); ?></option> <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, esc_attr( $this->get_option( $key ) ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
@ -700,8 +712,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Multiselect HTML. * Generate Multiselect HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -728,20 +740,20 @@ abstract class WC_Settings_API {
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php echo $this->get_tooltip_html( $data ); ?> <?php echo $this->get_tooltip_html( $data ); // WPCS: XSS ok. ?>
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label> <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<fieldset> <fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend> <legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>[]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>> <select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field_key ); ?>[]" id="<?php echo esc_attr( $field_key ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); // WPCS: XSS ok. ?>>
<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?> <?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( in_array( $option_key, $value ), true ); ?>><?php echo esc_attr( $option_value ); ?></option> <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( in_array( $option_key, $value, true ), true ); ?>><?php echo esc_attr( $option_value ); ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); // WPCS: XSS ok. ?>
<?php if ( $data['select_buttons'] ) : ?> <?php if ( $data['select_buttons'] ) : ?>
<br/><a class="select_all button" href="#"><?php _e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'woocommerce' ); ?></a> <br/><a class="select_all button" href="#"><?php esc_html_e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php esc_html_e( 'Select none', 'woocommerce' ); ?></a>
<?php endif; ?> <?php endif; ?>
</fieldset> </fieldset>
</td> </td>
@ -754,8 +766,8 @@ abstract class WC_Settings_API {
/** /**
* Generate Title HTML. * Generate Title HTML.
* *
* @param mixed $key * @param string $key Field key.
* @param mixed $data * @param array $data Field data.
* @since 1.0.0 * @since 1.0.0
* @return string * @return string
*/ */
@ -786,8 +798,8 @@ abstract class WC_Settings_API {
* *
* Make sure the data is escaped correctly, etc. * Make sure the data is escaped correctly, etc.
* *
* @param string $key Field key * @param string $key Field key.
* @param string|null $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_text_field( $key, $value ) { public function validate_text_field( $key, $value ) {
@ -800,8 +812,8 @@ abstract class WC_Settings_API {
* *
* Make sure the data is escaped correctly, etc. * Make sure the data is escaped correctly, etc.
* *
* @param string $key * @param string $key Field key.
* @param string|null $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_price_field( $key, $value ) { public function validate_price_field( $key, $value ) {
@ -814,8 +826,8 @@ abstract class WC_Settings_API {
* *
* Make sure the data is escaped correctly, etc. * Make sure the data is escaped correctly, etc.
* *
* @param string $key * @param string $key Field key.
* @param string|null $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_decimal_field( $key, $value ) { public function validate_decimal_field( $key, $value ) {
@ -826,8 +838,8 @@ abstract class WC_Settings_API {
/** /**
* Validate Password Field. No input sanitization is used to avoid corrupting passwords. * Validate Password Field. No input sanitization is used to avoid corrupting passwords.
* *
* @param string $key * @param string $key Field key.
* @param string|null $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_password_field( $key, $value ) { public function validate_password_field( $key, $value ) {
@ -838,8 +850,8 @@ abstract class WC_Settings_API {
/** /**
* Validate Textarea Field. * Validate Textarea Field.
* *
* @param string $key * @param string $key Field key.
* @param string|null $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_textarea_field( $key, $value ) { public function validate_textarea_field( $key, $value ) {
@ -847,7 +859,12 @@ abstract class WC_Settings_API {
return wp_kses( trim( stripslashes( $value ) ), return wp_kses( trim( stripslashes( $value ) ),
array_merge( array_merge(
array( array(
'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true ), 'iframe' => array(
'src' => true,
'style' => true,
'id' => true,
'class' => true,
),
), ),
wp_kses_allowed_html( 'post' ) wp_kses_allowed_html( 'post' )
) )
@ -859,8 +876,8 @@ abstract class WC_Settings_API {
* *
* If not set, return "no", otherwise return "yes". * If not set, return "no", otherwise return "yes".
* *
* @param string $key * @param string $key Field key.
* @param string|null $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_checkbox_field( $key, $value ) { public function validate_checkbox_field( $key, $value ) {
@ -870,8 +887,8 @@ abstract class WC_Settings_API {
/** /**
* Validate Select Field. * Validate Select Field.
* *
* @param string $key * @param string $key Field key.
* @param string $value Posted Value * @param string $value Posted Value.
* @return string * @return string
*/ */
public function validate_select_field( $key, $value ) { public function validate_select_field( $key, $value ) {
@ -882,8 +899,8 @@ abstract class WC_Settings_API {
/** /**
* Validate Multiselect Field. * Validate Multiselect Field.
* *
* @param string $key * @param string $key Field key.
* @param string $value Posted Value * @param string $value Posted Value.
* @return string|array * @return string|array
*/ */
public function validate_multiselect_field( $key, $value ) { public function validate_multiselect_field( $key, $value ) {
@ -892,9 +909,9 @@ abstract class WC_Settings_API {
/** /**
* Validate the data on the "Settings" form. * Validate the data on the "Settings" form.
* @deprecated 2.6.0 No longer used
* *
* @param array $form_fields * @deprecated 2.6.0 No longer used.
* @param array $form_fields Array of fields.
*/ */
public function validate_settings_fields( $form_fields = array() ) { public function validate_settings_fields( $form_fields = array() ) {
wc_deprecated_function( 'validate_settings_fields', '2.6' ); wc_deprecated_function( 'validate_settings_fields', '2.6' );
@ -902,8 +919,9 @@ abstract class WC_Settings_API {
/** /**
* Format settings if needed. * Format settings if needed.
* @deprecated 2.6.0 Unused *
* @param array $value * @deprecated 2.6.0 Unused.
* @param array $value Value to format.
* @return array * @return array
*/ */
public function format_settings( $value ) { public function format_settings( $value ) {

View File

@ -244,7 +244,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
} }
wp_localize_script( 'wc-shipping-zone-methods', 'shippingZoneMethodsLocalizeScript', array( wp_localize_script( 'wc-shipping-zone-methods', 'shippingZoneMethodsLocalizeScript', array(
'methods' => $zone->get_shipping_methods(), 'methods' => $zone->get_shipping_methods( false, 'json' ),
'zone_name' => $zone->get_zone_name(), 'zone_name' => $zone->get_zone_name(),
'zone_id' => $zone->get_id(), 'zone_id' => $zone->get_id(),
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ), 'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),

View File

@ -184,49 +184,55 @@ function woocommerce_wp_checkbox( $field ) {
/** /**
* Output a select input box. * Output a select input box.
* *
* @param array $field * @param array $field Data about the field to render.
*/ */
function woocommerce_wp_select( $field ) { function woocommerce_wp_select( $field ) {
global $thepostid, $post; global $thepostid, $post;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short'; $field = wp_parse_args( $field, array(
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; 'class' => 'select short',
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; 'style' => '',
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true ); 'wrapper_class' => '',
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 'value' => get_post_meta( $thepostid, $field['id'], true ),
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; 'name' => $field['id'],
'desc_tip' => false,
'custom_attributes' => array(),
) );
// Custom attribute handling $wrapper_attributes = array(
$custom_attributes = array(); 'class' => $field['wrapper_class'] . " form-field {$field['id']}_field",
);
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { $label_attributes = array(
'for' => $field['id'],
);
foreach ( $field['custom_attributes'] as $attribute => $value ) { $field_attributes = (array) $field['custom_attributes'];
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; $field_attributes['style'] = $field['style'];
} $field_attributes['id'] = $field['id'];
} $field_attributes['name'] = $field['name'];
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
echo wc_help_tip( $field['description'] );
}
echo '<select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" ' . implode( ' ', $custom_attributes ) . '>';
$tooltip = ! empty( $field['description'] ) && false !== $field['desc_tip'] ? $field['description'] : '';
$description = ! empty( $field['description'] ) && false === $field['desc_tip'] ? $field['description'] : '';
?>
<p <?php echo wc_implode_html_attributes( $wrapper_attributes ); // WPCS: XSS ok. ?>>
<label <?php echo wc_implode_html_attributes( $label_attributes ); // WPCS: XSS ok. ?>><?php echo wp_kses_post( $field['label'] ); ?></label>
<?php if ( $tooltip ) : ?>
<?php echo wc_help_tip( $tooltip ); // WPCS: XSS ok. ?>
<?php endif; ?>
<select <?php echo wc_implode_html_attributes( $field_attributes ); // WPCS: XSS ok. ?>>
<?php
foreach ( $field['options'] as $key => $value ) { foreach ( $field['options'] as $key => $value ) {
echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>'; echo '<option value="' . esc_attr( $key ) . '" ' . selected( $field['value'] === $key || ( is_array( $field['value'] ) && in_array( $key, $field['value'], true ) ), true, false ) . '>' . esc_html( $value ) . '</option>';
} }
?>
echo '</select> '; </select>
<?php if ( $description ) : ?>
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { <span class="description"><?php echo wp_kses_post( $description ); ?></span>
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; <?php endif; ?>
} </p>
<?php
echo '</p>';
} }
/** /**

View File

@ -2449,7 +2449,7 @@ class WC_AJAX {
'instance_id' => $instance_id, 'instance_id' => $instance_id,
'zone_id' => $zone->get_id(), 'zone_id' => $zone->get_id(),
'zone_name' => $zone->get_zone_name(), 'zone_name' => $zone->get_zone_name(),
'methods' => $zone->get_shipping_methods(), 'methods' => $zone->get_shipping_methods( false, 'json' ),
) ); ) );
} }
@ -2547,7 +2547,7 @@ class WC_AJAX {
wp_send_json_success( array( wp_send_json_success( array(
'zone_id' => $zone->get_id(), 'zone_id' => $zone->get_id(),
'zone_name' => $zone->get_zone_name(), 'zone_name' => $zone->get_zone_name(),
'methods' => $zone->get_shipping_methods(), 'methods' => $zone->get_shipping_methods( false, 'json' ),
) ); ) );
} }
@ -2579,7 +2579,7 @@ class WC_AJAX {
wp_send_json_success( array( wp_send_json_success( array(
'zone_id' => $zone->get_id(), 'zone_id' => $zone->get_id(),
'zone_name' => $zone->get_zone_name(), 'zone_name' => $zone->get_zone_name(),
'methods' => $zone->get_shipping_methods(), 'methods' => $zone->get_shipping_methods( false, 'json' ),
'errors' => $shipping_method->get_errors(), 'errors' => $shipping_method->get_errors(),
) ); ) );
} }

View File

@ -749,11 +749,11 @@ class WC_Customer extends WC_Legacy_Customer {
* Set customer's display name. * Set customer's display name.
* *
* @since 3.1.0 * @since 3.1.0
* @param string $display_name * @param string $display_name Display name.
* @throws WC_Data_Exception
*/ */
public function set_display_name( $display_name ) { public function set_display_name( $display_name ) {
$this->set_prop( 'display_name', $display_name ); /* translators: 1: first name 2: last name */
$this->set_prop( 'display_name', is_email( $display_name ) ? sprintf( __( '%1$s %2$s', 'display name', 'woocommerce' ), $this->get_first_name(), $this->get_last_name() ) : $display_name );
} }
/** /**

View File

@ -21,7 +21,7 @@ class WC_Download_Handler {
* Hook in methods. * Hook in methods.
*/ */
public static function init() { public static function init() {
if ( isset( $_GET['download_file'], $_GET['order'], $_GET['email'] ) ) { if ( isset( $_GET['download_file'], $_GET['order'] ) && ( isset( $_GET['email'] ) || isset( $_GET['uid'] ) ) ) {
add_action( 'init', array( __CLASS__, 'download_product' ) ); add_action( 'init', array( __CLASS__, 'download_product' ) );
} }
add_action( 'woocommerce_download_file_redirect', array( __CLASS__, 'download_file_redirect' ), 10, 2 ); add_action( 'woocommerce_download_file_redirect', array( __CLASS__, 'download_file_redirect' ), 10, 2 );
@ -41,8 +41,26 @@ class WC_Download_Handler {
self::download_error( __( 'Invalid download link.', 'woocommerce' ) ); self::download_error( __( 'Invalid download link.', 'woocommerce' ) );
} }
// Fallback, accept email address if it's passed.
if ( empty( $_GET['email'] ) && empty( $_GET['uid'] ) ) {
self::download_error( __( 'Invalid download link.', 'woocommerce' ) );
}
if ( isset( $_GET['email'] ) ) {
$email_address = $_GET['email'];
} else {
// Get email address from order to verify hash.
$order_id = wc_get_order_id_by_order_key( $_GET['order'] );
$order = wc_get_order( $order_id );
$email_address = is_a( $order, 'WC_Order' ) ? $order->get_billing_email() : null;
if ( is_null( $email_address ) || ! hash_equals( $_GET['uid'], hash( 'sha256', $email_address ) ) ) {
self::download_error( __( 'Invalid download link.', 'woocommerce' ) );
}
}
$download_ids = $data_store->get_downloads( array( $download_ids = $data_store->get_downloads( array(
'user_email' => sanitize_email( str_replace( ' ', '+', $_GET['email'] ) ), 'user_email' => sanitize_email( str_replace( ' ', '+', $email_address ) ),
'order_key' => wc_clean( $_GET['order'] ), 'order_key' => wc_clean( $_GET['order'] ),
'product_id' => $product_id, 'product_id' => $product_id,
'download_id' => wc_clean( preg_replace( '/\s+/', ' ', $_GET['key'] ) ), 'download_id' => wc_clean( preg_replace( '/\s+/', ' ', $_GET['key'] ) ),

View File

@ -188,31 +188,38 @@ class WC_Form_Handler {
return; return;
} }
$current_user = get_user_by( 'id', $user_id );
$current_first_name = $current_user->first_name;
$current_last_name = $current_user->last_name;
$current_email = $current_user->user_email;
$account_first_name = ! empty( $_POST['account_first_name'] ) ? wc_clean( $_POST['account_first_name'] ): ''; $account_first_name = ! empty( $_POST['account_first_name'] ) ? wc_clean( $_POST['account_first_name'] ): '';
$account_last_name = ! empty( $_POST['account_last_name'] ) ? wc_clean( $_POST['account_last_name'] ) : ''; $account_last_name = ! empty( $_POST['account_last_name'] ) ? wc_clean( $_POST['account_last_name'] ) : '';
$account_display_name = ! empty( $_POST['account_display_name'] ) ? wc_clean( $_POST['account_display_name'] ) : '';
$account_email = ! empty( $_POST['account_email'] ) ? wc_clean( $_POST['account_email'] ) : ''; $account_email = ! empty( $_POST['account_email'] ) ? wc_clean( $_POST['account_email'] ) : '';
$pass_cur = ! empty( $_POST['password_current'] ) ? $_POST['password_current'] : ''; $pass_cur = ! empty( $_POST['password_current'] ) ? $_POST['password_current'] : '';
$pass1 = ! empty( $_POST['password_1'] ) ? $_POST['password_1'] : ''; $pass1 = ! empty( $_POST['password_1'] ) ? $_POST['password_1'] : '';
$pass2 = ! empty( $_POST['password_2'] ) ? $_POST['password_2'] : ''; $pass2 = ! empty( $_POST['password_2'] ) ? $_POST['password_2'] : '';
$save_pass = true; $save_pass = true;
// Current user data.
$current_user = get_user_by( 'id', $user_id );
$current_first_name = $current_user->first_name;
$current_last_name = $current_user->last_name;
$current_email = $current_user->user_email;
// New user data.
$user = new stdClass(); $user = new stdClass();
$user->ID = $user_id; $user->ID = $user_id;
$user->first_name = $account_first_name; $user->first_name = $account_first_name;
$user->last_name = $account_last_name; $user->last_name = $account_last_name;
$user->display_name = $account_display_name;
// Prevent emails being displayed, or leave alone. // Prevent display name to be changed to email.
$user->display_name = is_email( $current_user->display_name ) ? $user->first_name : $current_user->display_name; if ( is_email( $account_display_name ) ) {
wc_add_notice( __( 'Display name cannot be changed to email address due to privacy concern.', 'woocommerce' ), 'error' );
}
// Handle required fields. // Handle required fields.
$required_fields = apply_filters( 'woocommerce_save_account_details_required_fields', array( $required_fields = apply_filters( 'woocommerce_save_account_details_required_fields', array(
'account_first_name' => __( 'First name', 'woocommerce' ), 'account_first_name' => __( 'First name', 'woocommerce' ),
'account_last_name' => __( 'Last name', 'woocommerce' ), 'account_last_name' => __( 'Last name', 'woocommerce' ),
'account_display_name' => __( 'Display name', 'woocommerce' ),
'account_email' => __( 'Email address', 'woocommerce' ), 'account_email' => __( 'Email address', 'woocommerce' ),
) ); ) );

View File

@ -170,7 +170,7 @@ class WC_Frontend_Scripts {
'flexslider' => array( 'flexslider' => array(
'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ), 'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
'deps' => array( 'jquery' ), 'deps' => array( 'jquery' ),
'version' => '2.6.1', 'version' => '2.7.0',
), ),
'js-cookie' => array( 'js-cookie' => array(
'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ), 'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),

View File

@ -387,7 +387,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
$files[ $download_id ]['download_url'] = add_query_arg( array( $files[ $download_id ]['download_url'] = add_query_arg( array(
'download_file' => $product_id, 'download_file' => $product_id,
'order' => $order->get_order_key(), 'order' => $order->get_order_key(),
'email' => urlencode( $order->get_billing_email() ), 'uid' => hash( 'sha256', $order->get_billing_email() ),
'key' => $download_id, 'key' => $download_id,
), trailingslashit( home_url() ) ); ), trailingslashit( home_url() ) );
} }

View File

@ -2,14 +2,11 @@
/** /**
* Regular order * Regular order
* *
* @author Automattic
* @package WooCommerce\Classes * @package WooCommerce\Classes
* @version 2.2.0 * @version 2.2.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { defined( 'ABSPATH' ) || exit;
exit;
}
/** /**
* Order Class. * Order Class.
@ -1406,16 +1403,24 @@ class WC_Order extends WC_Abstract_Order {
* Orders which only contain virtual, downloadable items do not need admin * Orders which only contain virtual, downloadable items do not need admin
* intervention. * intervention.
* *
* Uses a transient so these calls are not repeated multiple times, and because
* once the order is processed this code/transient does not need to persist.
*
* @since 3.0.0 * @since 3.0.0
* @return bool * @return bool
*/ */
public function needs_processing() { public function needs_processing() {
$needs_processing = false; $transient_name = 'wc_order_' . $this->get_id() . '_needs_processing';
$needs_processing = get_transient( $transient_name );
if ( false === $needs_processing ) {
$needs_processing = 0;
if ( count( $this->get_items() ) > 0 ) { if ( count( $this->get_items() ) > 0 ) {
foreach ( $this->get_items() as $item ) { foreach ( $this->get_items() as $item ) {
if ( $item->is_type( 'line_item' ) ) { if ( $item->is_type( 'line_item' ) ) {
$product = $item->get_product(); $product = $item->get_product();
if ( ! $product ) { if ( ! $product ) {
continue; continue;
} }
@ -1423,14 +1428,17 @@ class WC_Order extends WC_Abstract_Order {
$virtual_downloadable_item = $product->is_downloadable() && $product->is_virtual(); $virtual_downloadable_item = $product->is_downloadable() && $product->is_virtual();
if ( apply_filters( 'woocommerce_order_item_needs_processing', ! $virtual_downloadable_item, $product, $this->get_id() ) ) { if ( apply_filters( 'woocommerce_order_item_needs_processing', ! $virtual_downloadable_item, $product, $this->get_id() ) ) {
$needs_processing = true; $needs_processing = 1;
break; break;
} }
} }
} }
} }
return $needs_processing; set_transient( $transient_name, $needs_processing, DAY_IN_SECONDS );
}
return 1 === absint( $needs_processing );
} }
/* /*

View File

@ -1,36 +1,38 @@
<?php <?php
include_once( 'legacy/class-wc-legacy-shipping-zone.php' );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Represents a single shipping zone * Represents a single shipping zone
* *
* @class WC_Shipping_Zone
* @since 2.6.0 * @since 2.6.0
* @version 3.0.0 * @version 3.0.0
* @package WooCommerce/Classes * @package WooCommerce/Classes
* @category Class */
* @author WooCommerce
defined( 'ABSPATH' ) || exit;
require_once 'legacy/class-wc-legacy-shipping-zone.php';
/**
* WC_Shipping_Zone class.
*/ */
class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone { class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Zone ID * Zone ID
*
* @var int|null * @var int|null
*/ */
protected $id = null; protected $id = null;
/** /**
* This is the name of this object type. * This is the name of this object type.
*
* @var string * @var string
*/ */
protected $object_type = 'shipping_zone'; protected $object_type = 'shipping_zone';
/** /**
* Zone Data * Zone Data.
*
* @var array * @var array
*/ */
protected $data = array( protected $data = array(
@ -49,7 +51,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
$this->set_id( $zone ); $this->set_id( $zone );
} elseif ( is_object( $zone ) ) { } elseif ( is_object( $zone ) ) {
$this->set_id( $zone->zone_id ); $this->set_id( $zone->zone_id );
} elseif ( 0 === $zone || "0" === $zone ) { } elseif ( 0 === $zone || '0' === $zone ) {
$this->set_id( 0 ); $this->set_id( 0 );
} else { } else {
$this->set_object_read( true ); $this->set_object_read( true );
@ -61,16 +63,16 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
} }
} }
/* /**
|-------------------------------------------------------------------------- * --------------------------------------------------------------------------
| Getters * Getters
|-------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
/** /**
* Get zone name. * Get zone name.
* *
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_zone_name( $context = 'view' ) { public function get_zone_name( $context = 'view' ) {
@ -80,7 +82,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Get zone order. * Get zone order.
* *
* @param string $context * @param string $context View or edit context.
* @return int * @return int
*/ */
public function get_zone_order( $context = 'view' ) { public function get_zone_order( $context = 'view' ) {
@ -90,7 +92,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Get zone locations. * Get zone locations.
* *
* @param string $context * @param string $context View or edit context.
* @return array of zone objects * @return array of zone objects
*/ */
public function get_zone_locations( $context = 'view' ) { public function get_zone_locations( $context = 'view' ) {
@ -100,8 +102,8 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Return a text string representing what this zone is for. * Return a text string representing what this zone is for.
* *
* @param int $max * @param int $max Max locations to return.
* @param string $context * @param string $context View or edit context.
* @return string * @return string
*/ */
public function get_formatted_location( $max = 10, $context = 'view' ) { public function get_formatted_location( $max = 10, $context = 'view' ) {
@ -135,8 +137,8 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
// Fix display of encoded characters. // Fix display of encoded characters.
$location_parts = array_map( 'html_entity_decode', $location_parts ); $location_parts = array_map( 'html_entity_decode', $location_parts );
if ( sizeof( $location_parts ) > $max ) { if ( count( $location_parts ) > $max ) {
$remaining = sizeof( $location_parts ) - $max; $remaining = count( $location_parts ) - $max;
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
return sprintf( _n( '%s and %d other region', '%s and %d other regions', $remaining, 'woocommerce' ), implode( ', ', array_splice( $location_parts, 0, $max ) ), $remaining ); return sprintf( _n( '%s and %d other region', '%s and %d other regions', $remaining, 'woocommerce' ), implode( ', ', array_splice( $location_parts, 0, $max ) ), $remaining );
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
@ -150,10 +152,11 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Get shipping methods linked to this zone. * Get shipping methods linked to this zone.
* *
* @param bool Only return enabled methods. * @param bool $enabled_only Only return enabled methods.
* @param string $context Getting shipping methods for what context. Valid values, admin, json.
* @return array of objects * @return array of objects
*/ */
public function get_shipping_methods( $enabled_only = false ) { public function get_shipping_methods( $enabled_only = false, $context = 'admin' ) {
if ( null === $this->get_id() ) { if ( null === $this->get_id() ) {
return array(); return array();
} }
@ -166,29 +169,36 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
foreach ( $raw_methods as $raw_method ) { foreach ( $raw_methods as $raw_method ) {
if ( in_array( $raw_method->method_id, array_keys( $allowed_classes ), true ) ) { if ( in_array( $raw_method->method_id, array_keys( $allowed_classes ), true ) ) {
$class_name = $allowed_classes[ $raw_method->method_id ]; $class_name = $allowed_classes[ $raw_method->method_id ];
$instance_id = $raw_method->instance_id;
// The returned array may contain instances of shipping methods, as well // The returned array may contain instances of shipping methods, as well
// as classes. If the "class" is an instance, just use it. If not, // as classes. If the "class" is an instance, just use it. If not,
// create an instance. // create an instance.
if ( is_object( $class_name ) ) { if ( is_object( $class_name ) ) {
$class_name_of_instance = get_class( $class_name ); $class_name_of_instance = get_class( $class_name );
$methods[ $raw_method->instance_id ] = new $class_name_of_instance( $raw_method->instance_id ); $methods[ $instance_id ] = new $class_name_of_instance( $instance_id );
} else { } else {
// If the class is not an object, it should be a string. It's better // If the class is not an object, it should be a string. It's better
// to double check, to be sure (a class must be a string, anything) // to double check, to be sure (a class must be a string, anything)
// else would be useless // else would be useless.
if ( is_string( $class_name ) && class_exists( $class_name ) ) { if ( is_string( $class_name ) && class_exists( $class_name ) ) {
$methods[ $raw_method->instance_id ] = new $class_name( $raw_method->instance_id ); $methods[ $instance_id ] = new $class_name( $instance_id );
} }
} }
// Let's make sure that we have an instance before setting its attributes // Let's make sure that we have an instance before setting its attributes.
if ( is_object( $methods[ $raw_method->instance_id ] ) ) { if ( is_object( $methods[ $instance_id ] ) ) {
$methods[ $raw_method->instance_id ]->method_order = absint( $raw_method->method_order ); $methods[ $instance_id ]->method_order = absint( $raw_method->method_order );
$methods[ $raw_method->instance_id ]->enabled = $raw_method->is_enabled ? 'yes' : 'no'; $methods[ $instance_id ]->enabled = $raw_method->is_enabled ? 'yes' : 'no';
$methods[ $raw_method->instance_id ]->has_settings = $methods[ $raw_method->instance_id ]->has_settings(); $methods[ $instance_id ]->has_settings = $methods[ $instance_id ]->has_settings();
$methods[ $raw_method->instance_id ]->settings_html = $methods[ $raw_method->instance_id ]->supports( 'instance-settings-modal' ) ? $methods[ $raw_method->instance_id ]->get_admin_options_html() : false; $methods[ $instance_id ]->settings_html = $methods[ $instance_id ]->supports( 'instance-settings-modal' ) ? $methods[ $instance_id ]->get_admin_options_html(): false;
$methods[ $raw_method->instance_id ]->method_description = wp_kses_post( wpautop( $methods[ $raw_method->instance_id ]->method_description ) ); $methods[ $instance_id ]->method_description = wp_kses_post( wpautop( $methods[ $instance_id ]->method_description ) );
}
if ( 'json' === $context ) {
// We don't want the entire object in this context, just the public props.
$methods[ $instance_id ] = (object) get_object_vars( $methods[ $instance_id ] );
unset( $methods[ $instance_id ]->instance_form_fields, $methods[ $instance_id ]->form_fields );
} }
} }
} }
@ -198,25 +208,25 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
return apply_filters( 'woocommerce_shipping_zone_shipping_methods', $methods, $raw_methods, $allowed_classes, $this ); return apply_filters( 'woocommerce_shipping_zone_shipping_methods', $methods, $raw_methods, $allowed_classes, $this );
} }
/* /**
|-------------------------------------------------------------------------- * --------------------------------------------------------------------------
| Setters * Setters
|-------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
/** /**
* Set zone name. * Set zone name.
* *
* @param string $set * @param string $set Value to set.
*/ */
public function set_zone_name( $set ) { public function set_zone_name( $set ) {
$this->set_prop( 'zone_name', wc_clean( $set ) ); $this->set_prop( 'zone_name', wc_clean( $set ) );
} }
/** /**
* Set zone order. * Set zone order. Value to set.
* *
* @param int $set * @param int $set Value to set.
*/ */
public function set_zone_order( $set ) { public function set_zone_order( $set ) {
$this->set_prop( 'zone_order', absint( $set ) ); $this->set_prop( 'zone_order', absint( $set ) );
@ -226,7 +236,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
* Set zone locations. * Set zone locations.
* *
* @since 3.0.0 * @since 3.0.0
* @param array * @param array $locations Value to set.
*/ */
public function set_zone_locations( $locations ) { public function set_zone_locations( $locations ) {
if ( 0 !== $this->get_id() ) { if ( 0 !== $this->get_id() ) {
@ -234,10 +244,10 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
} }
} }
/* /**
|-------------------------------------------------------------------------- * --------------------------------------------------------------------------
| Other Methods * Other
|-------------------------------------------------------------------------- * --------------------------------------------------------------------------
*/ */
/** /**
@ -280,7 +290,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Location type detection. * Location type detection.
* *
* @param object $location * @param object $location Location to check.
* @return boolean * @return boolean
*/ */
private function location_is_continent( $location ) { private function location_is_continent( $location ) {
@ -290,7 +300,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Location type detection. * Location type detection.
* *
* @param object $location * @param object $location Location to check.
* @return boolean * @return boolean
*/ */
private function location_is_country( $location ) { private function location_is_country( $location ) {
@ -300,7 +310,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Location type detection. * Location type detection.
* *
* @param object $location * @param object $location Location to check.
* @return boolean * @return boolean
*/ */
private function location_is_state( $location ) { private function location_is_state( $location ) {
@ -310,7 +320,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Location type detection. * Location type detection.
* *
* @param object $location * @param object $location Location to check.
* @return boolean * @return boolean
*/ */
private function location_is_postcode( $location ) { private function location_is_postcode( $location ) {
@ -320,18 +330,18 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Is passed location type valid? * Is passed location type valid?
* *
* @param string $type * @param string $type Type to check.
* @return boolean * @return boolean
*/ */
public function is_valid_location_type( $type ) { public function is_valid_location_type( $type ) {
return in_array( $type, array( 'postcode', 'state', 'country', 'continent' ) ); return in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true );
} }
/** /**
* Add location (state or postcode) to a zone. * Add location (state or postcode) to a zone.
* *
* @param string $code * @param string $code Location code.
* @param string $type state or postcode * @param string $type state or postcode.
*/ */
public function add_location( $code, $type ) { public function add_location( $code, $type ) {
if ( 0 !== $this->get_id() && $this->is_valid_location_type( $type ) ) { if ( 0 !== $this->get_id() && $this->is_valid_location_type( $type ) ) {
@ -352,7 +362,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Clear all locations for this zone. * Clear all locations for this zone.
* *
* @param array|string $types of location to clear * @param array|string $types of location to clear.
*/ */
public function clear_locations( $types = array( 'postcode', 'state', 'country', 'continent' ) ) { public function clear_locations( $types = array( 'postcode', 'state', 'country', 'continent' ) ) {
if ( ! is_array( $types ) ) { if ( ! is_array( $types ) ) {
@ -360,7 +370,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
} }
$zone_locations = $this->get_prop( 'zone_locations', 'edit' ); $zone_locations = $this->get_prop( 'zone_locations', 'edit' );
foreach ( $zone_locations as $key => $values ) { foreach ( $zone_locations as $key => $values ) {
if ( in_array( $values->type, $types ) ) { if ( in_array( $values->type, $types, true ) ) {
unset( $zone_locations[ $key ] ); unset( $zone_locations[ $key ] );
} }
} }
@ -371,7 +381,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Set locations. * Set locations.
* *
* @param array $locations Array of locations * @param array $locations Array of locations.
*/ */
public function set_locations( $locations = array() ) { public function set_locations( $locations = array() ) {
$this->clear_locations(); $this->clear_locations();
@ -383,7 +393,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Add a shipping method to this zone. * Add a shipping method to this zone.
* *
* @param string $type shipping method type * @param string $type shipping method type.
* @return int new instance_id, 0 on failure * @return int new instance_id, 0 on failure
*/ */
public function add_shipping_method( $type ) { public function add_shipping_method( $type ) {
@ -396,7 +406,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
$allowed_classes = $wc_shipping->get_shipping_method_class_names(); $allowed_classes = $wc_shipping->get_shipping_method_class_names();
$count = $this->data_store->get_method_count( $this->get_id() ); $count = $this->data_store->get_method_count( $this->get_id() );
if ( in_array( $type, array_keys( $allowed_classes ) ) ) { if ( in_array( $type, array_keys( $allowed_classes ), true ) ) {
$instance_id = $this->data_store->add_method( $this->get_id(), $type, $count + 1 ); $instance_id = $this->data_store->add_method( $this->get_id(), $type, $count + 1 );
} }
@ -412,7 +422,7 @@ class WC_Shipping_Zone extends WC_Legacy_Shipping_Zone {
/** /**
* Delete a shipping method from a zone. * Delete a shipping method from a zone.
* *
* @param int $instance_id * @param int $instance_id Shipping method instance ID.
* @return True on success, false on failure * @return True on success, false on failure
*/ */
public function delete_shipping_method( $instance_id ) { public function delete_shipping_method( $instance_id ) {

View File

@ -114,7 +114,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
wp_update_user( apply_filters( 'woocommerce_update_customer_args', array( wp_update_user( apply_filters( 'woocommerce_update_customer_args', array(
'ID' => $customer->get_id(), 'ID' => $customer->get_id(),
'role' => $customer->get_role(), 'role' => $customer->get_role(),
'display_name' => $customer->get_first_name() . ' ' . $customer->get_last_name(), 'display_name' => $customer->get_display_name(),
), $customer ) ); ), $customer ) );
$wp_user = new WP_User( $customer->get_id() ); $wp_user = new WP_User( $customer->get_id() );
$customer->set_date_created( $wp_user->user_registered ); $customer->set_date_created( $wp_user->user_registered );

View File

@ -49,19 +49,22 @@ class WC_Order_Item_Product_Data_Store extends Abstract_WC_Order_Item_Type_Data_
*/ */
public function save_item_data( &$item ) { public function save_item_data( &$item ) {
$id = $item->get_id(); $id = $item->get_id();
$save_values = array( $changes = $item->get_changes();
'_product_id' => $item->get_product_id( 'edit' ), $meta_key_to_props = array(
'_variation_id' => $item->get_variation_id( 'edit' ), '_product_id' => 'product_id',
'_qty' => $item->get_quantity( 'edit' ), '_variation_id' => 'variation_id',
'_tax_class' => $item->get_tax_class( 'edit' ), '_qty' => 'quantity',
'_line_subtotal' => $item->get_subtotal( 'edit' ), '_tax_class' => 'tax_class',
'_line_subtotal_tax' => $item->get_subtotal_tax( 'edit' ), '_line_subtotal' => 'subtotal',
'_line_total' => $item->get_total( 'edit' ), '_line_subtotal_tax' => 'subtotal_tax',
'_line_tax' => $item->get_total_tax( 'edit' ), '_line_total' => 'total',
'_line_tax_data' => $item->get_taxes( 'edit' ), '_line_tax' => 'total_tax',
'_line_tax_data' => 'taxes',
); );
foreach ( $save_values as $key => $value ) { $props_to_update = $this->get_props_to_update( $item, $meta_key_to_props, 'order_item' );
update_metadata( 'order_item', $id, $key, $value );
foreach ( $props_to_update as $meta_key => $prop ) {
update_metadata( 'order_item', $id, $meta_key, $item->{"get_$prop"}( 'edit' ) );
} }
} }

View File

@ -45,14 +45,17 @@ class WC_Order_Item_Shipping_Data_Store extends Abstract_WC_Order_Item_Type_Data
*/ */
public function save_item_data( &$item ) { public function save_item_data( &$item ) {
$id = $item->get_id(); $id = $item->get_id();
$save_values = array( $changes = $item->get_changes();
'method_id' => $item->get_method_id( 'edit' ), $meta_key_to_props = array(
'cost' => $item->get_total( 'edit' ), 'method_id' => 'method_id',
'total_tax' => $item->get_total_tax( 'edit' ), 'cost' => 'total',
'taxes' => $item->get_taxes( 'edit' ), 'total_tax' => 'total_tax',
'taxes' => 'taxes',
); );
foreach ( $save_values as $key => $value ) { $props_to_update = $this->get_props_to_update( $item, $meta_key_to_props, 'order_item' );
update_metadata( 'order_item', $id, $key, $value );
foreach ( $props_to_update as $meta_key => $prop ) {
update_metadata( 'order_item', $id, $meta_key, $item->{"get_$prop"}( 'edit' ) );
} }
} }
} }

View File

@ -47,15 +47,18 @@ class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Stor
*/ */
public function save_item_data( &$item ) { public function save_item_data( &$item ) {
$id = $item->get_id(); $id = $item->get_id();
$save_values = array( $changes = $item->get_changes();
'rate_id' => $item->get_rate_id( 'edit' ), $meta_key_to_props = array(
'label' => $item->get_label( 'edit' ), 'rate_id' => 'rate_id',
'compound' => $item->get_compound( 'edit' ), 'label' => 'label',
'tax_amount' => $item->get_tax_total( 'edit' ), 'compound' => 'compound',
'shipping_tax_amount' => $item->get_shipping_tax_total( 'edit' ), 'tax_amount' => 'tax_total',
'shipping_tax_amount' => 'shipping_tax_total',
); );
foreach ( $save_values as $key => $value ) { $props_to_update = $this->get_props_to_update( $item, $meta_key_to_props, 'order_item' );
update_metadata( 'order_item', $id, $key, $value );
foreach ( $props_to_update as $meta_key => $prop ) {
update_metadata( 'order_item', $id, $meta_key, $item->{"get_$prop"}( 'edit' ) );
} }
} }
} }

View File

@ -810,13 +810,27 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
global $wpdb; global $wpdb;
$decimals = absint( wc_get_price_decimals() ); $decimals = absint( wc_get_price_decimals() );
$exclude_term_ids = array();
$outofstock_join = '';
$outofstock_where = '';
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && $product_visibility_term_ids['outofstock'] ) {
$exclude_term_ids[] = $product_visibility_term_ids['outofstock'];
}
if ( count( $exclude_term_ids ) ) {
$outofstock_join = " LEFT JOIN ( SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', array_map( 'absint', $exclude_term_ids ) ) . ' ) ) AS exclude_join ON exclude_join.object_id = id';
$outofstock_where = ' AND exclude_join.object_id IS NULL';
}
// @codingStandardsIgnoreStart.
return $wpdb->get_results( return $wpdb->get_results(
$wpdb->prepare( $wpdb->prepare(
"SELECT post.ID as id, post.post_parent as parent_id FROM `$wpdb->posts` AS post "SELECT post.ID as id, post.post_parent as parent_id FROM `$wpdb->posts` AS post
LEFT JOIN `$wpdb->postmeta` AS meta ON post.ID = meta.post_id LEFT JOIN `$wpdb->postmeta` AS meta ON post.ID = meta.post_id
LEFT JOIN `$wpdb->postmeta` AS meta2 ON post.ID = meta2.post_id LEFT JOIN `$wpdb->postmeta` AS meta2 ON post.ID = meta2.post_id
$outofstock_join
WHERE post.post_type IN ( 'product', 'product_variation' ) WHERE post.post_type IN ( 'product', 'product_variation' )
AND post.post_status = 'publish' AND post.post_status = 'publish'
AND meta.meta_key = '_sale_price' AND meta.meta_key = '_sale_price'
@ -824,11 +838,13 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
AND CAST( meta.meta_value AS DECIMAL ) >= 0 AND CAST( meta.meta_value AS DECIMAL ) >= 0
AND CAST( meta.meta_value AS CHAR ) != '' AND CAST( meta.meta_value AS CHAR ) != ''
AND CAST( meta.meta_value AS DECIMAL( 10, %d ) ) = CAST( meta2.meta_value AS DECIMAL( 10, %d ) ) AND CAST( meta.meta_value AS DECIMAL( 10, %d ) ) = CAST( meta2.meta_value AS DECIMAL( 10, %d ) )
$outofstock_where
GROUP BY post.ID", GROUP BY post.ID",
$decimals, $decimals,
$decimals $decimals
) )
); );
// @codingStandardsIgnoreEnd.
} }
/** /**
@ -1304,7 +1320,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
* @param string $term Search term. * @param string $term Search term.
* @param string $type Type of product. * @param string $type Type of product.
* @param bool $include_variations Include variations in search or not. * @param bool $include_variations Include variations in search or not.
* @param bool $all_statuses Should we search all statuses or limit to published? * @param bool $all_statuses Should we search all statuses or limit to published.
* @return array of ids * @return array of ids
*/ */
public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false ) { public function search_products( $term, $type = '', $include_variations = false, $all_statuses = false ) {

View File

@ -1,25 +1,29 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Flat Rate Shipping Method. * Flat Rate Shipping Method.
* *
* @class WC_Shipping_Flat_Rate
* @version 2.6.0 * @version 2.6.0
* @package WooCommerce/Classes/Shipping * @package WooCommerce/Classes/Shipping
* @author WooThemes */
defined( 'ABSPATH' ) || exit;
/**
* WC_Shipping_Flat_Rate class.
*/ */
class WC_Shipping_Flat_Rate extends WC_Shipping_Method { class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
/** @var string cost passed to [fee] shortcode */ /**
* Cost passed to [fee] shortcode.
*
* @var string Cost.
*/
protected $fee_cost = ''; protected $fee_cost = '';
/** /**
* Constructor. * Constructor.
* *
* @param int $instance_id * @param int $instance_id Shipping method instance ID.
*/ */
public function __construct( $instance_id = 0 ) { public function __construct( $instance_id = 0 ) {
$this->id = 'flat_rate'; $this->id = 'flat_rate';
@ -37,10 +41,10 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
} }
/** /**
* init user set variables. * Init user set variables.
*/ */
public function init() { public function init() {
$this->instance_form_fields = include( 'includes/settings-flat-rate.php' ); $this->instance_form_fields = include 'includes/settings-flat-rate.php';
$this->title = $this->get_option( 'title' ); $this->title = $this->get_option( 'title' );
$this->tax_status = $this->get_option( 'tax_status' ); $this->tax_status = $this->get_option( 'tax_status' );
$this->cost = $this->get_option( 'cost' ); $this->cost = $this->get_option( 'cost' );
@ -49,20 +53,21 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
/** /**
* Evaluate a cost from a sum/string. * Evaluate a cost from a sum/string.
* @param string $sum *
* @param array $args * @param string $sum Sum of shipping.
* @param array $args Args.
* @return string * @return string
*/ */
protected function evaluate_cost( $sum, $args = array() ) { protected function evaluate_cost( $sum, $args = array() ) {
include_once( WC()->plugin_path() . '/includes/libraries/class-wc-eval-math.php' ); include_once WC()->plugin_path() . '/includes/libraries/class-wc-eval-math.php';
// Allow 3rd parties to process shipping cost arguments // Allow 3rd parties to process shipping cost arguments.
$args = apply_filters( 'woocommerce_evaluate_shipping_cost_args', $args, $sum, $this ); $args = apply_filters( 'woocommerce_evaluate_shipping_cost_args', $args, $sum, $this );
$locale = localeconv(); $locale = localeconv();
$decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' ); $decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',' );
$this->fee_cost = $args['cost']; $this->fee_cost = $args['cost'];
// Expand shortcodes // Expand shortcodes.
add_shortcode( 'fee', array( $this, 'fee' ) ); add_shortcode( 'fee', array( $this, 'fee' ) );
$sum = do_shortcode( str_replace( $sum = do_shortcode( str_replace(
@ -79,22 +84,23 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
remove_shortcode( 'fee', array( $this, 'fee' ) ); remove_shortcode( 'fee', array( $this, 'fee' ) );
// Remove whitespace from string // Remove whitespace from string.
$sum = preg_replace( '/\s+/', '', $sum ); $sum = preg_replace( '/\s+/', '', $sum );
// Remove locale from string // Remove locale from string.
$sum = str_replace( $decimals, '.', $sum ); $sum = str_replace( $decimals, '.', $sum );
// Trim invalid start/end characters // Trim invalid start/end characters.
$sum = rtrim( ltrim( $sum, "\t\n\r\0\x0B+*/" ), "\t\n\r\0\x0B+-*/" ); $sum = rtrim( ltrim( $sum, "\t\n\r\0\x0B+*/" ), "\t\n\r\0\x0B+-*/" );
// Do the math // Do the math.
return $sum ? WC_Eval_Math::evaluate( $sum ) : 0; return $sum ? WC_Eval_Math::evaluate( $sum ) : 0;
} }
/** /**
* Work out fee (shortcode). * Work out fee (shortcode).
* @param array $atts *
* @param array $atts Attributes.
* @return string * @return string
*/ */
public function fee( $atts ) { public function fee( $atts ) {
@ -122,9 +128,9 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
} }
/** /**
* calculate_shipping function. * Calculate the shipping costs.
* *
* @param array $package (default: array()) * @param array $package Package of items from cart.
*/ */
public function calculate_shipping( $package = array() ) { public function calculate_shipping( $package = array() ) {
$rate = array( $rate = array(
@ -134,7 +140,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
'package' => $package, 'package' => $package,
); );
// Calculate the costs // Calculate the costs.
$has_costs = false; // True when a cost is set. False if all costs are blank strings. $has_costs = false; // True when a cost is set. False if all costs are blank strings.
$cost = $this->get_option( 'cost' ); $cost = $this->get_option( 'cost' );
@ -154,7 +160,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
$highest_class_cost = 0; $highest_class_cost = 0;
foreach ( $found_shipping_classes as $shipping_class => $products ) { foreach ( $found_shipping_classes as $shipping_class => $products ) {
// Also handles BW compatibility when slugs were used instead of ids // Also handles BW compatibility when slugs were used instead of ids.
$shipping_class_term = get_term_by( 'slug', $shipping_class, 'product_shipping_class' ); $shipping_class_term = get_term_by( 'slug', $shipping_class, 'product_shipping_class' );
$class_cost_string = $shipping_class_term && $shipping_class_term->term_id ? $this->get_option( 'class_cost_' . $shipping_class_term->term_id, $this->get_option( 'class_cost_' . $shipping_class, '' ) ) : $this->get_option( 'no_class_cost', '' ); $class_cost_string = $shipping_class_term && $shipping_class_term->term_id ? $this->get_option( 'class_cost_' . $shipping_class_term->term_id, $this->get_option( 'class_cost_' . $shipping_class, '' ) ) : $this->get_option( 'no_class_cost', '' );
@ -180,7 +186,6 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
} }
} }
// Add the rate
if ( $has_costs ) { if ( $has_costs ) {
$this->add_rate( $rate ); $this->add_rate( $rate );
} }
@ -190,27 +195,14 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
* *
* Previously there were (overly complex) options to add additional rates however this was not user. * Previously there were (overly complex) options to add additional rates however this was not user.
* friendly and goes against what Flat Rate Shipping was originally intended for. * friendly and goes against what Flat Rate Shipping was originally intended for.
*
* This example shows how you can add an extra rate based on this flat rate via custom function:
*
* add_action( 'woocommerce_flat_rate_shipping_add_rate', 'add_another_custom_flat_rate', 10, 2 );
*
* function add_another_custom_flat_rate( $method, $rate ) {
* $new_rate = $rate;
* $new_rate['id'] .= ':' . 'custom_rate_name'; // Append a custom ID.
* $new_rate['label'] = 'Rushed Shipping'; // Rename to 'Rushed Shipping'.
* $new_rate['cost'] += 2; // Add $2 to the cost.
*
* // Add it to WC.
* $method->add_rate( $new_rate );
* }.
*/ */
do_action( 'woocommerce_' . $this->id . '_shipping_add_rate', $this, $rate ); do_action( 'woocommerce_' . $this->id . '_shipping_add_rate', $this, $rate );
} }
/** /**
* Get items in package. * Get items in package.
* @param array $package *
* @param array $package Package of items from cart.
* @return int * @return int
*/ */
public function get_package_item_qty( $package ) { public function get_package_item_qty( $package ) {
@ -225,7 +217,8 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
/** /**
* Finds and returns shipping classes and the products with said class. * Finds and returns shipping classes and the products with said class.
* @param mixed $package *
* @param mixed $package Package of items from cart.
* @return array * @return array
*/ */
public function find_shipping_classes( $package ) { public function find_shipping_classes( $package ) {
@ -245,4 +238,18 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
return $found_shipping_classes; return $found_shipping_classes;
} }
/**
* Sanitize the cost field.
*
* @since 3.4.0
* @param string $value Unsanitized value.
* @return string
*/
public function sanitize_cost( $value ) {
$value = is_null( $value ) ? '' : $value;
$value = wp_kses_post( trim( wp_unslash( $value ) ) );
$value = str_replace( array( get_woocommerce_currency_symbol(), html_entity_decode( get_woocommerce_currency_symbol() ) ), '', $value );
return $value;
}
} }

View File

@ -1,14 +1,14 @@
<?php <?php
/**
* Settings for flat rate shipping.
*
* @package WooCommerce/Classes/Shipping
*/
if ( ! defined( 'ABSPATH' ) ) { defined( 'ABSPATH' ) || exit;
exit;
}
$cost_desc = __( 'Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>.', 'woocommerce' ) . '<br/><br/>' . __( 'Use <code>[qty]</code> for the number of items, <br/><code>[cost]</code> for the total cost of items, and <code>[fee percent="10" min_fee="20" max_fee=""]</code> for percentage based fees.', 'woocommerce' ); $cost_desc = __( 'Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>.', 'woocommerce' ) . '<br/><br/>' . __( 'Use <code>[qty]</code> for the number of items, <br/><code>[cost]</code> for the total cost of items, and <code>[fee percent="10" min_fee="20" max_fee=""]</code> for percentage based fees.', 'woocommerce' );
/**
* Settings for flat rate shipping.
*/
$settings = array( $settings = array(
'title' => array( 'title' => array(
'title' => __( 'Method title', 'woocommerce' ), 'title' => __( 'Method title', 'woocommerce' ),
@ -34,6 +34,7 @@ $settings = array(
'description' => $cost_desc, 'description' => $cost_desc,
'default' => '0', 'default' => '0',
'desc_tip' => true, 'desc_tip' => true,
'sanitize_callback' => array( $this, 'sanitize_cost' ),
), ),
); );
@ -44,6 +45,7 @@ if ( ! empty( $shipping_classes ) ) {
'title' => __( 'Shipping class costs', 'woocommerce' ), 'title' => __( 'Shipping class costs', 'woocommerce' ),
'type' => 'title', 'type' => 'title',
'default' => '', 'default' => '',
/* translators: %s: URL for link. */
'description' => sprintf( __( 'These costs can optionally be added based on the <a href="%s">product shipping class</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping&section=classes' ) ), 'description' => sprintf( __( 'These costs can optionally be added based on the <a href="%s">product shipping class</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping&section=classes' ) ),
); );
foreach ( $shipping_classes as $shipping_class ) { foreach ( $shipping_classes as $shipping_class ) {
@ -56,10 +58,12 @@ if ( ! empty( $shipping_classes ) ) {
'type' => 'text', 'type' => 'text',
'placeholder' => __( 'N/A', 'woocommerce' ), 'placeholder' => __( 'N/A', 'woocommerce' ),
'description' => $cost_desc, 'description' => $cost_desc,
'default' => $this->get_option( 'class_cost_' . $shipping_class->slug ), // Before 2.5.0, we used slug here which caused issues with long setting names 'default' => $this->get_option( 'class_cost_' . $shipping_class->slug ), // Before 2.5.0, we used slug here which caused issues with long setting names.
'desc_tip' => true, 'desc_tip' => true,
'sanitize_callback' => array( $this, 'sanitize_cost' ),
); );
} }
$settings['no_class_cost'] = array( $settings['no_class_cost'] = array(
'title' => __( 'No shipping class cost', 'woocommerce' ), 'title' => __( 'No shipping class cost', 'woocommerce' ),
'type' => 'text', 'type' => 'text',
@ -67,7 +71,9 @@ if ( ! empty( $shipping_classes ) ) {
'description' => $cost_desc, 'description' => $cost_desc,
'default' => '', 'default' => '',
'desc_tip' => true, 'desc_tip' => true,
'sanitize_callback' => array( $this, 'sanitize_cost' ),
); );
$settings['type'] = array( $settings['type'] = array(
'title' => __( 'Calculation type', 'woocommerce' ), 'title' => __( 'Calculation type', 'woocommerce' ),
'type' => 'select', 'type' => 'select',

View File

@ -348,7 +348,7 @@ function wc_cart_totals_fee_html( $fee ) {
function wc_cart_totals_shipping_method_label( $method ) { function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->get_label(); $label = $method->get_label();
if ( $method->cost > 0 ) { if ( $method->cost >= 0 && $method->get_method_id() !== 'free_shipping' ) {
if ( WC()->cart->display_prices_including_tax() ) { if ( WC()->cart->display_prices_including_tax() ) {
$label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() ); $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) { if ( $method->get_shipping_tax() > 0 && ! wc_prices_include_tax() ) {

View File

@ -1309,3 +1309,18 @@ function wc_array_merge_recursive_numeric() {
return $final; return $final;
} }
/**
* Implode and escape HTML attributes for output.
*
* @since 3.3.0
* @param array $raw_attributes Attribute name value pairs.
* @return string
*/
function wc_implode_html_attributes( $raw_attributes ) {
$attributes = array();
foreach ( $raw_attributes as $name => $value ) {
$attributes[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
}
return implode( ' ', $attributes );
}

View File

@ -380,7 +380,7 @@ add_action( 'after_switch_theme', 'wc_reset_product_grid_settings' );
*/ */
function wc_get_loop_class() { function wc_get_loop_class() {
$loop_index = wc_get_loop_prop( 'loop', 0 ); $loop_index = wc_get_loop_prop( 'loop', 0 );
$columns = wc_get_loop_prop( 'columns', wc_get_default_products_per_row() ); $columns = absint( max( 1, wc_get_loop_prop( 'columns', wc_get_default_products_per_row() ) ) );
$loop_index ++; $loop_index ++;
wc_set_loop_prop( 'loop', $loop_index ); wc_set_loop_prop( 'loop', $loop_index );
@ -518,21 +518,6 @@ function wc_query_string_form_fields( $values = null, $exclude = array(), $curre
} }
} }
/**
* Implode and escape HTML attributes for output.
*
* @since 3.3.0
* @param array $raw_attributes Attribute name value pairs.
* @return string
*/
function wc_implode_html_attributes( $raw_attributes ) {
$attributes = array();
foreach ( $raw_attributes as $name => $value ) {
$attributes[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
}
return implode( ' ', $attributes );
}
/** /**
* Template pages * Template pages
*/ */

View File

@ -160,14 +160,26 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woocommerce/wo
== Changelog == == Changelog ==
= 3.4.0 - 2018-XX-XX = = 3.4.0 - 2018-XX-XX =
* Feature - Added a new order widget to the dashboard (on multisite) so you can see your orders across multiple stores on the same WordPress network. - #17598 * Feature - Added a new order widget to the dashboard (on multisite) so you can see your orders across multiple stores on the same WordPress network. #17598
* Feature - Added "display name" input on the My Account page. #19078
* Tweak - Made the system status tool which purges user carts also purge persistent carts. * Tweak - Made the system status tool which purges user carts also purge persistent carts.
* Tweak - Fixed settings table styling on mobile. * Tweak - Fixed settings table styling on mobile.
* Tweak - Don't call WC_Install::install() on downgrades. * Tweak - Don't call WC_Install::install() on downgrades.
* Tweak - Added a function to return a list of custom tables to aid with cleanup. * Tweak - Added a function to return a list of custom tables to aid with cleanup.
* Tweak - Display whether or not external object cache is enabled in system status report. * Tweak - Display whether or not external object cache is enabled in system status report.
* Tweak - Standardize stock update messages in admin and correctly log who performed the action. When an order note is added after modifying stock manually, update order notes display via AJAX. * Tweak - Standardize stock update messages in admin and correctly log who performed the action. When an order note is added after modifying stock manually, update order notes display via AJAX.
* Tweak - Added a santization function for flat rate costs to remove currency symbols.
* Tweak - Display zero value when using shipping classes.
* Tweak - Updated Flexslider to version 2.7.0.
* Tweak - Make sure terms page exists and isnt trashed before using it.
* Tweak - Hash customer email address in download URLs to protect privacy.
* Fix - Properly set orderby and order when calling WC_Customer_Download_Data_Store::get_downloads(). * Fix - Properly set orderby and order when calling WC_Customer_Download_Data_Store::get_downloads().
* Fix - Set maxlength for order item meta key to avoid values disapearing if too long.
* Fix - Remove hardcoded /wp-content check for downloads.
* Fix - Prevent shortcode [product_page] redirecting to the actual product's page after add to cart.
* Fix - Make the "main term" logic match for both the breadcrumb and product categories widget.
* Fix - Check parent status too when seeing if variation is purchasable.
* Fix - Made get_on_sale_products respect the setting to hide outofstock products.
* Dev - Gallery meta box is now powered by CRUD. * Dev - Gallery meta box is now powered by CRUD.
* Dev - Added support for additional HTML5 input types for settings/checkout forms. * Dev - Added support for additional HTML5 input types for settings/checkout forms.
* Dev - Made 'woocommerce_email_downloads_column_' hook format aware. * Dev - Made 'woocommerce_email_downloads_column_' hook format aware.
@ -176,6 +188,11 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woocommerce/wo
* Dev - Added CSS classname to grouped product table. * Dev - Added CSS classname to grouped product table.
* Dev - Mini cart item link now respects value of $product_permalink. * Dev - Mini cart item link now respects value of $product_permalink.
* Dev - Add missing `woocommerce_update_options__` actions for settings pages that override save method. * Dev - Add missing `woocommerce_update_options__` actions for settings pages that override save method.
* Dev - Added `woocommerce_persistent_cart_enabled` filter.
* Dev - Refactor woocommerce_wp_select so it could be used for a multiselect.
* Dev - Added ability to declare sanitize_callback in settings API.
* Template - Update cart coupon button from input to button type.
* Performance - Optimized saving of orders. Adds a transient for needs_processing, and only saves changes when saving order items.
* Localization - Various spelling and grammar fixes. * Localization - Various spelling and grammar fixes.
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce/master/CHANGELOG.txt). [See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce/master/CHANGELOG.txt).

View File

@ -13,7 +13,7 @@
* @see https://docs.woocommerce.com/document/template-structure/ * @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes * @author WooThemes
* @package WooCommerce/Templates * @package WooCommerce/Templates
* @version 3.3.0 * @version 3.4.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
@ -130,7 +130,7 @@ do_action( 'woocommerce_before_cart' ); ?>
<?php if ( wc_coupons_enabled() ) { ?> <?php if ( wc_coupons_enabled() ) { ?>
<div class="coupon"> <div class="coupon">
<label for="coupon_code"><?php esc_html_e( 'Coupon:', 'woocommerce' ); ?></label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" /> <input type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>" /> <label for="coupon_code"><?php esc_html_e( 'Coupon:', 'woocommerce' ); ?></label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="<?php esc_attr_e( 'Coupon code', 'woocommerce' ); ?>" /> <button type="submit" class="button" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?></button>
<?php do_action( 'woocommerce_cart_coupon' ); ?> <?php do_action( 'woocommerce_cart_coupon' ); ?>
</div> </div>
<?php } ?> <?php } ?>

View File

@ -4,17 +4,17 @@
* *
* @author WooThemes * @author WooThemes
* @package WooCommerce/Templates * @package WooCommerce/Templates
* @version 3.1.1 * @version 3.4.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
$terms_page_id = wc_get_page_id( 'terms' ); $terms_page = wc_get_page_id( 'terms' ) > 0 ? get_post( wc_get_page_id( 'terms' ) ) : false;
if ( $terms_page_id > 0 && apply_filters( 'woocommerce_checkout_show_terms', true ) ) : if ( $terms_page && 'publish' === $terms_page->post_status && apply_filters( 'woocommerce_checkout_show_terms', true ) ) :
$terms = get_post( $terms_page_id ); $terms_content = has_shortcode( $terms_page->post_content, 'woocommerce_checkout' ) ? '' : wc_format_content( $terms_page->post_content );
$terms_content = has_shortcode( $terms->post_content, 'woocommerce_checkout' ) ? '' : wc_format_content( $terms->post_content );
if ( $terms_content ) { if ( $terms_content ) {
do_action( 'woocommerce_checkout_before_terms_and_conditions' ); do_action( 'woocommerce_checkout_before_terms_and_conditions' );

View File

@ -11,27 +11,30 @@
* the readme will list any important changes. * the readme will list any important changes.
* *
* @see https://docs.woocommerce.com/document/template-structure/ * @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain * @package WooCommerce/Templates/Emails/Plain
* @version 3.2.1 * @version 3.4.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
echo "\n" . strtoupper( __( 'Billing address', 'woocommerce' ) ) . "\n\n"; echo "\n" . esc_html( wc_strtoupper( __( 'Billing address', 'woocommerce' ) ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $order->get_formatted_billing_address() ) . "\n"; echo preg_replace( '#<br\s*/?>#i', "\n", $order->get_formatted_billing_address() ) . "\n"; // WPCS: XSS ok.
if ( $order->get_billing_phone() ) { if ( $order->get_billing_phone() ) {
echo $order->get_billing_phone() . "\n"; echo $order->get_billing_phone() . "\n"; // WPCS: XSS ok.
} }
if ( $order->get_billing_email() ) { if ( $order->get_billing_email() ) {
echo $order->get_billing_email() . "\n"; echo $order->get_billing_email() . "\n"; // WPCS: XSS ok.
} }
if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && ( $shipping = $order->get_formatted_shipping_address() ) ) { if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() ) {
echo "\n" . strtoupper( __( 'Shipping address', 'woocommerce' ) ) . "\n\n"; $shipping = $order->get_formatted_shipping_address();
echo preg_replace( '#<br\s*/?>#i', "\n", $shipping ) . "\n";
if ( $shipping ) {
echo "\n" . esc_html( wc_strtoupper( __( 'Shipping address', 'woocommerce' ) ) ) . "\n\n";
echo preg_replace( '#<br\s*/?>#i', "\n", $shipping ) . "\n"; // WPCS: XSS ok.
}
} }

View File

@ -13,16 +13,15 @@
* the readme will list any important changes. * the readme will list any important changes.
* *
* @see https://docs.woocommerce.com/document/template-structure/ * @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain * @package WooCommerce/Templates/Emails/Plain
* @version 2.5.0 * @version 3.4.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
echo strtoupper( __( 'Customer details', 'woocommerce' ) ) . "\n\n"; echo esc_html( wc_strtoupper( __( 'Customer details', 'woocommerce' ) ) ) . "\n\n";
foreach ( $fields as $field ) { foreach ( $fields as $field ) {
echo wp_kses_post( $field['label'] ) . ': ' . wp_kses_post( $field['value'] ) . "\n"; echo wp_kses_post( $field['label'] ) . ': ' . wp_kses_post( $field['value'] ) . "\n";

View File

@ -12,7 +12,7 @@
* *
* @see https://docs.woocommerce.com/document/template-structure/ * @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates/Emails * @package WooCommerce/Templates/Emails
* @version 3.3.0 * @version 3.4.0
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email ); do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );
/* translators: %s: Order ID. */ /* translators: %s: Order ID. */
echo wp_kses_post( strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) ) . "\n"; echo wp_kses_post( wc_strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) ) . "\n";
echo wc_format_datetime( $order->get_date_created() ) . "\n"; // WPCS: XSS ok. echo wc_format_datetime( $order->get_date_created() ) . "\n"; // WPCS: XSS ok.
echo "\n" . wc_get_email_order_items( $order, array( // WPCS: XSS ok. echo "\n" . wc_get_email_order_items( $order, array( // WPCS: XSS ok.
'show_sku' => $sent_to_admin, 'show_sku' => $sent_to_admin,

View File

@ -36,6 +36,12 @@ do_action( 'woocommerce_before_edit_account_form' ); ?>
</p> </p>
<div class="clear"></div> <div class="clear"></div>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_display_name"><?php esc_html_e( 'Display name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="account_display_name" id="account_display_name" value="<?php echo esc_attr( $user->display_name ); ?>" /> <span><em><?php esc_html_e( 'This will be how your name will be displayed in the account section and in reviews', 'woocommerce' ); ?></em></span>
</p>
<div class="clear"></div>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_email"><?php esc_html_e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label> <label for="account_email"><?php esc_html_e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" value="<?php echo esc_attr( $user->user_email ); ?>" /> <input type="email" class="woocommerce-Input woocommerce-Input--email input-text" name="account_email" id="account_email" value="<?php echo esc_attr( $user->user_email ); ?>" />