Merge branch 'master' into update/order-details-4
This commit is contained in:
commit
73189340c8
|
@ -1453,6 +1453,30 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$this->update_taxes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate fees for all line items.
|
||||
*/
|
||||
public function calculate_fees() {
|
||||
// Sum fee costs.
|
||||
$fees_total = 0;
|
||||
|
||||
foreach ( $this->get_fees() as $item ) {
|
||||
$fee_total = $item->get_total();
|
||||
|
||||
if ( 0 > $fee_total ) {
|
||||
$max_discount = round( $cart_total + $fees_total + $shipping_total, wc_get_price_decimals() ) * -1;
|
||||
|
||||
if ( $fee_total < $max_discount && 0 > $max_discount ) {
|
||||
$item->set_total( $max_discount );
|
||||
}
|
||||
}
|
||||
|
||||
$fees_total += $item->get_total();
|
||||
}
|
||||
|
||||
return $fees_total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update tax lines for the order based on the line item taxes themselves.
|
||||
*/
|
||||
|
@ -1554,7 +1578,6 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
public function calculate_totals( $and_taxes = true ) {
|
||||
do_action( 'woocommerce_order_before_calculate_totals', $and_taxes, $this );
|
||||
|
||||
$fees_total = 0;
|
||||
$shipping_total = 0;
|
||||
$cart_subtotal_tax = 0;
|
||||
$cart_total_tax = 0;
|
||||
|
@ -1570,19 +1593,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$this->set_shipping_total( $shipping_total );
|
||||
|
||||
// Sum fee costs.
|
||||
foreach ( $this->get_fees() as $item ) {
|
||||
$fee_total = $item->get_total();
|
||||
|
||||
if ( 0 > $fee_total ) {
|
||||
$max_discount = round( $cart_total + $fees_total + $shipping_total, wc_get_price_decimals() ) * -1;
|
||||
|
||||
if ( $fee_total < $max_discount && 0 > $max_discount ) {
|
||||
$item->set_total( $max_discount );
|
||||
}
|
||||
}
|
||||
|
||||
$fees_total += $item->get_total();
|
||||
}
|
||||
$fees_total = $this->calculate_fees();
|
||||
|
||||
// Calculate taxes for items, shipping, discounts. Note; this also triggers save().
|
||||
if ( $and_taxes ) {
|
||||
|
|
Loading…
Reference in New Issue