WordPress at Your Fingertips
function is not described

WC_Cart_Totals::get_tax_class_costs() protected WC 3.2.0

Get item costs grouped by tax class.

{} It's a method of the class: WC_Cart_Totals{}

No Hooks.

Return

Array.

Usage

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

Changelog

Since 3.2.0 Introduced.

Code of WC_Cart_Totals::get_tax_class_costs() WC 5.9.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 );
}