Use get_displayed_subtotal() to determine if conditions for coupons and free shipping is met.

@claudiosmweb

Closes #10711
This commit is contained in:
Mike Jolley 2016-04-18 11:39:00 +01:00
parent 5ce2ab7cfa
commit a77735432b
3 changed files with 25 additions and 7 deletions

View File

@ -790,6 +790,28 @@ class WC_Cart {
return array_unique( $found_tax_classes );
}
/**
* Determines the value that the customer spent and the subtotal
* displayed, used for things like coupon validation.
*
* Since the coupon lines are displayed based on the TAX DISPLAY value
* of cart, this is used to determine the spend.
*
* If cart totals are shown including tax, use the subtotal.
* If cart totals are shown excluding tax, use the subtotal ex tax
* (tax is shown after coupons).
*
* @since 2.6.0
* @return string
*/
public function get_displayed_subtotal() {
if ( 'incl' === $this->tax_display_cart ) {
return wc_format_decimal( $this->subtotal );
} elseif ( 'excl' === $this->tax_display_cart ) {
return wc_format_decimal( $this->subtotal_ex_tax );
}
}
/*-----------------------------------------------------------------------------------*/
/* Add to cart handling */
/*-----------------------------------------------------------------------------------*/

View File

@ -392,7 +392,7 @@ class WC_Coupon {
* @throws Exception
*/
private function validate_minimum_amount() {
if ( $this->minimum_amount > 0 && wc_format_decimal( $this->minimum_amount ) > wc_format_decimal( WC()->cart->subtotal ) ) {
if ( $this->minimum_amount > 0 && apply_filters( 'woocommerce_coupon_validate_minimum_amount', wc_format_decimal( $this->minimum_amount ) > WC()->cart->get_displayed_subtotal(), $this ) ) {
throw new Exception( self::E_WC_COUPON_MIN_SPEND_LIMIT_NOT_MET );
}
}
@ -403,7 +403,7 @@ class WC_Coupon {
* @throws Exception
*/
private function validate_maximum_amount() {
if ( $this->maximum_amount > 0 && wc_format_decimal( $this->maximum_amount ) < wc_format_decimal( WC()->cart->subtotal ) ) {
if ( $this->maximum_amount > 0 && apply_filters( 'woocommerce_coupon_validate_maximum_amount', wc_format_decimal( $this->maximum_amount ) <= WC()->cart->get_displayed_subtotal(), $this ) ) {
throw new Exception( self::E_WC_COUPON_MAX_SPEND_LIMIT_MET );
}
}

View File

@ -112,11 +112,7 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
}
if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ) ) && isset( WC()->cart->cart_contents_total ) ) {
if ( WC()->cart->prices_include_tax ) {
$total = WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes );
} else {
$total = WC()->cart->cart_contents_total;
}
$total = WC()->cart->get_displayed_subtotal();
if ( $total >= $this->min_amount ) {
$has_met_min_amount = true;