WC_Cart_Totals::get_item_costs_by_tax_class
Get item costs grouped by tax class.
Method of the class: WC_Cart_Totals{}
No Hooks.
Returns
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() WC Cart Totals::get item costs by tax class code WC 10.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;
}