WC_Cart_Totals::get_tax_class_costs()protectedWC 3.2.0

Get item costs grouped by tax class.

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

Хуков нет.

Возвращает

Массив.

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

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

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

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

Код WC_Cart_Totals::get_tax_class_costs() WC 8.7.0

protected function get_tax_class_costs() {
	$item_tax_classes     = wp_list_pluck( $this->items, 'tax_class' );
	$shipping_tax_classes = wp_list_pluck( $this->shipping, 'tax_class' );
	$fee_tax_classes      = wp_list_pluck( $this->fees, 'tax_class' );
	$costs                = array_fill_keys( $item_tax_classes + $shipping_tax_classes + $fee_tax_classes, 0 );
	$costs['non-taxable'] = 0;

	foreach ( $this->items + $this->fees + $this->shipping as $item ) {
		if ( 0 > $item->total ) {
			continue;
		}
		if ( ! $item->taxable ) {
			$costs['non-taxable'] += $item->total;
		} elseif ( 'inherit' === $item->tax_class ) {
			$costs[ reset( $item_tax_classes ) ] += $item->total;
		} else {
			$costs[ $item->tax_class ] += $item->total;
		}
	}
	return array_filter( $costs );
}