WC_Order_Item_Fee::get_tax_class_costs()protectedWC 3.2.0

Get item costs grouped by tax class.

Метод класса: WC_Order_Item_Fee{}

Хуков нет.

Возвращает

Массив.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_tax_class_costs( $order );
$order(WC_Order) (обязательный)
Order object.

Список изменений

С версии 3.2.0 Введена.

Код WC_Order_Item_Fee::get_tax_class_costs() WC 8.7.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 );
}