WordPress at Your Fingertips
function is not described

WC_Order_Item_Fee::get_tax_class_costs() protected WC 3.2.0

Get item costs grouped by tax class.

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

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_tax_class_costs( $order );
$order(WC_Order) (required)
Order object.

Changelog

Since 3.2.0 Introduced.

Code of WC_Order_Item_Fee::get_tax_class_costs() WC 5.9.0

protected function get_tax_class_costs( $order ) {
	$order_item_tax_classes = $order->get_items_tax_classes();
	$costs                  = array_fill_keys( $order_item_tax_classes, 0 );
	$costs['non-taxable']   = 0;

	foreach ( $order->get_items( array( 'line_item', 'fee', 'shipping' ) ) as $item ) {
		if ( 0 > $item->get_total() ) {
			continue;
		}
		if ( 'taxable' !== $item->get_tax_status() ) {
			$costs['non-taxable'] += $item->get_total();
		} elseif ( 'inherit' === $item->get_tax_class() ) {
			$inherit_class            = reset( $order_item_tax_classes );
			$costs[ $inherit_class ] += $item->get_total();
		} else {
			$costs[ $item->get_tax_class() ] += $item->get_total();
		}
	}

	return array_filter( $costs );
}