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

WC_Cart_Totals::calculate_item_totals() WC 3.2.0

Calculate item totals.

Это метод класса: WC_Cart_Totals

Возвращает

Null. Ничего.

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

$WC_Cart_Totals = new WC_Cart_Totals();
$var = $WC_Cart_Totals->calculate_item_totals();

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

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

Код WC Cart Totals::calculate item totals: woocommerce/includes/class-wc-cart-totals.php WC 3.6.5

<?php
protected function calculate_item_totals() {
	$this->get_items_from_cart();
	$this->calculate_item_subtotals();
	$this->calculate_discounts();

	foreach ( $this->items as $item_key => $item ) {
		$item->total     = $this->get_discounted_price_in_cents( $item_key );
		$item->total_tax = 0;

		if ( has_filter( 'woocommerce_get_discounted_price' ) ) {
			/**
			 * Allow plugins to filter this price like in the legacy cart class.
			 *
			 * This is legacy and should probably be deprecated in the future.
			 * $item->object is the cart item object.
			 * $this->cart is the cart object.
			 */
			$item->total = wc_add_number_precision(
				apply_filters( 'woocommerce_get_discounted_price', wc_remove_number_precision( $item->total ), $item->object, $this->cart )
			);
		}

		if ( $this->calculate_tax && $item->product->is_taxable() ) {
			$total_taxes     = apply_filters( 'woocommerce_calculate_item_totals_taxes', WC_Tax::calc_tax( $item->total, $item->tax_rates, $item->price_includes_tax ), $item, $this );
			$item->taxes     = $total_taxes;
			$item->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $item->taxes ) );

			if ( $item->price_includes_tax ) {
				// Use unrounded taxes so we can re-calculate from the orders screen accurately later.
				$item->total = $item->total - array_sum( $item->taxes );
			}
		}

		$this->cart->cart_contents[ $item_key ]['line_tax_data']['total'] = wc_remove_number_precision_deep( $item->taxes );
		$this->cart->cart_contents[ $item_key ]['line_total']             = wc_remove_number_precision( $item->total );
		$this->cart->cart_contents[ $item_key ]['line_tax']               = wc_remove_number_precision( $item->total_tax );
	}

	$this->set_total( 'items_total', array_sum( array_map( 'round', array_values( wp_list_pluck( $this->items, 'total' ) ) ) ) );
	$this->set_total( 'items_total_tax', array_sum( array_values( wp_list_pluck( $this->items, 'total_tax' ) ) ) );

	$this->cart->set_cart_contents_total( $this->get_total( 'items_total' ) );
	$this->cart->set_cart_contents_tax( array_sum( $this->get_merged_taxes( false, 'items' ) ) );
	$this->cart->set_cart_contents_taxes( $this->get_merged_taxes( false, 'items' ) );
}