WC_Cart_Totals::get_item_costs_by_tax_class()protectedWC 3.2.0

Get item costs grouped by tax class.

Method of the class: WC_Cart_Totals{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_item_costs_by_tax_class();

Changelog

Since 3.2.0 Introduced.

WC_Cart_Totals::get_item_costs_by_tax_class() code WC 8.7.0

protected function get_item_costs_by_tax_class() {
	$tax_classes = array(
		'non-taxable' => 0,
	);

	foreach ( $this->items + $this->fees + $this->shipping as $item ) {
		if ( ! isset( $tax_classes[ $item->tax_class ] ) ) {
			$tax_classes[ $item->tax_class ] = 0;
		}

		if ( $item->taxable ) {
			$tax_classes[ $item->tax_class ] += $item->total;
		} else {
			$tax_classes['non-taxable'] += $item->total;
		}
	}

	return $tax_classes;
}