WC_Cart_Totals::get_tax_class_costs
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_tax_class_costs();
Changelog
| Since 3.2.0 | Introduced. |
WC_Cart_Totals::get_tax_class_costs() WC Cart Totals::get tax class costs code WC 10.3.6
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 );
}