WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Abstract_Order::calculate_totals() public WC 2.2

Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.

{} Это метод класса: WC_Abstract_Order{}

Возвращает

float. calculated grand total.

Использование

$WC_Abstract_Order = new WC_Abstract_Order();
$WC_Abstract_Order->calculate_totals( $and_taxes );
$and_taxes(true/false)
Calc taxes if true.
По умолчанию: true

Список изменений

С версии 2.2 Введена.

Код WC_Abstract_Order::calculate_totals() WC 4.7.1

<?php
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;

	$cart_subtotal = $this->get_cart_subtotal_for_order();
	$cart_total    = $this->get_cart_total_for_order();

	// Sum shipping costs.
	foreach ( $this->get_shipping_methods() as $shipping ) {
		$shipping_total += NumberUtil::round( $shipping->get_total(), wc_get_price_decimals() );
	}

	$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 = NumberUtil::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();
	}

	// Calculate taxes for items, shipping, discounts. Note; this also triggers save().
	if ( $and_taxes ) {
		$this->calculate_taxes();
	}

	// Sum taxes again so we can work out how much tax was discounted. This uses original values, not those possibly rounded to 2dp.
	foreach ( $this->get_items() as $item ) {
		$taxes = $item->get_taxes();

		foreach ( $taxes['total'] as $tax_rate_id => $tax ) {
			$cart_total_tax += (float) $tax;
		}

		foreach ( $taxes['subtotal'] as $tax_rate_id => $tax ) {
			$cart_subtotal_tax += (float) $tax;
		}
	}

	$this->set_discount_total( NumberUtil::round( $cart_subtotal - $cart_total, wc_get_price_decimals() ) );
	$this->set_discount_tax( wc_round_tax_total( $cart_subtotal_tax - $cart_total_tax ) );
	$this->set_total( NumberUtil::round( $cart_total + $fees_total + $this->get_shipping_total() + $this->get_cart_tax() + $this->get_shipping_tax(), wc_get_price_decimals() ) );

	do_action( 'woocommerce_order_after_calculate_totals', $and_taxes, $this );

	$this->save();

	return $this->get_total();
}