Merge pull request #19291 from Chunkford/patch-1
Moving cart rounding discount function to core functions
This commit is contained in:
commit
bd2188e87c
|
@ -379,7 +379,7 @@ class WC_Discounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$discount = wc_cart_round_discount( min( $discounted_price, $discount ), 0 );
|
$discount = wc_round_discount( min( $discounted_price, $discount ), 0 );
|
||||||
$cart_total = $cart_total + $price_to_discount;
|
$cart_total = $cart_total + $price_to_discount;
|
||||||
$total_discount = $total_discount + $discount;
|
$total_discount = $total_discount + $discount;
|
||||||
$applied_count = $applied_count + $apply_quantity;
|
$applied_count = $applied_count + $apply_quantity;
|
||||||
|
@ -389,7 +389,7 @@ class WC_Discounts {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work out how much discount would have been given to the cart as a whole and compare to what was discounted on all line items.
|
// Work out how much discount would have been given to the cart as a whole and compare to what was discounted on all line items.
|
||||||
$cart_total_discount = wc_cart_round_discount( $cart_total * ( $coupon_amount / 100 ), 0 );
|
$cart_total_discount = wc_round_discount( $cart_total * ( $coupon_amount / 100 ), 0 );
|
||||||
|
|
||||||
if ( $total_discount < $cart_total_discount && $adjust_final_discount ) {
|
if ( $total_discount < $cart_total_discount && $adjust_final_discount ) {
|
||||||
$total_discount += $this->apply_coupon_remainder( $coupon, $items_to_apply, $cart_total_discount - $total_discount );
|
$total_discount += $this->apply_coupon_remainder( $coupon, $items_to_apply, $cart_total_discount - $total_discount );
|
||||||
|
|
|
@ -374,13 +374,7 @@ function wc_cart_totals_shipping_method_label( $method ) {
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
function wc_cart_round_discount( $value, $precision ) {
|
function wc_cart_round_discount( $value, $precision ) {
|
||||||
if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
|
return wc_round_discount( $value, $precision );
|
||||||
return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE );
|
|
||||||
} elseif ( 2 === WC_DISCOUNT_ROUNDING_MODE ) {
|
|
||||||
return wc_legacy_round_half_down( $value, $precision );
|
|
||||||
} else {
|
|
||||||
return round( $value, $precision );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2060,3 +2060,20 @@ function wc_decimal_to_fraction( $decimal ) {
|
||||||
|
|
||||||
return array( $numerator, $denominator );
|
return array( $numerator, $denominator );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Round discount.
|
||||||
|
*
|
||||||
|
* @param double $value Amount to round.
|
||||||
|
* @param int $precision DP to round.
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
function wc_round_discount( $value, $precision ) {
|
||||||
|
if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
|
||||||
|
return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE );
|
||||||
|
} elseif ( 2 === WC_DISCOUNT_ROUNDING_MODE ) {
|
||||||
|
return wc_legacy_round_half_down( $value, $precision );
|
||||||
|
} else {
|
||||||
|
return round( $value, $precision );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue