WC_Order_Item_Fee::get_tax_class_costs()
Get item costs grouped by tax class.
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. |
WC_Order_Item_Fee::get_tax_class_costs() WC Order Item Fee::get tax class costs code WC 9.2.3
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 ); }