Automattic\WooCommerce\Internal\RestApi\Routes\V4\Refunds

DataUtils::build_tax_rates_arrayprivateWC 1.0

Build tax rate array from order tax items for use with WC_Tax calculations.

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

Хуков нет.

Возвращает

Массив. Tax rates array formatted for WC_Tax::calc_*_tax() methods.

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

// private - только в коде основоного (родительского) класса
$result = $this->build_tax_rates_array( $order, $tax_ids ): array;
$order(WC_Order) (обязательный)
The order.
$tax_ids(массив) (обязательный)
Array of tax rate IDs that apply to an item.

Код DataUtils::build_tax_rates_array() WC 10.5.2

private function build_tax_rates_array( WC_Order $order, array $tax_ids ): array {
	$tax_rates = array();
	$tax_items = $order->get_items( 'tax' );

	foreach ( $tax_ids as $tax_id ) {
		foreach ( $tax_items as $tax_item ) {
			if ( $tax_item->get_rate_id() === (int) $tax_id ) {
				$tax_rates[ $tax_id ] = array(
					'rate'     => $tax_item->get_rate_percent(),
					'label'    => $tax_item->get_label(),
					'compound' => $tax_item->is_compound() ? 'yes' : 'no',
				);
				break;
			}
		}
	}

	return $tax_rates;
}