WC_Cart_Totals::calculate_totals()protectedWC 3.2.0

Main cart totals.

Метод класса: WC_Cart_Totals{}

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->calculate_totals();

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

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

Код WC_Cart_Totals::calculate_totals() WC 8.7.0

protected function calculate_totals() {
	$this->set_total( 'total', NumberUtil::round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_merged_taxes( true ) ), 0 ) );
	$items_tax = array_sum( $this->get_merged_taxes( false, array( 'items' ) ) );
	// Shipping and fee taxes are rounded separately because they were entered excluding taxes (as opposed to item prices, which may or may not be including taxes depending upon settings).
	$shipping_and_fee_taxes = NumberUtil::round( array_sum( $this->get_merged_taxes( false, array( 'fees', 'shipping' ) ) ), wc_get_price_decimals() );
	$this->cart->set_total_tax( $items_tax + $shipping_and_fee_taxes );

	// Allow plugins to hook and alter totals before final total is calculated.
	if ( has_action( 'woocommerce_calculate_totals' ) ) {
		do_action( 'woocommerce_calculate_totals', $this->cart );
	}

	// Allow plugins to filter the grand total, and sum the cart totals in case of modifications.
	$this->cart->set_total( max( 0, apply_filters( 'woocommerce_calculated_total', $this->get_total( 'total' ), $this->cart ) ) );
}