Automattic\WooCommerce\Internal\RestApi\Routes\V4\Refunds
DataUtils::build_tax_rates_array
Build tax rate array from order tax items for use with WC_Tax calculations.
Method of the class: DataUtils{}
No Hooks.
Returns
Array. Tax rates array formatted for WC_Tax::calc_*_tax() methods.
Usage
// private - for code of main (parent) class only $result = $this->build_tax_rates_array( $order, $tax_ids ): array;
- $order(WC_Order) (required)
- The order.
- $tax_ids(array) (required)
- Array of tax rate IDs that apply to an item.
DataUtils::build_tax_rates_array() DataUtils::build tax rates array code WC 10.9.4
private function build_tax_rates_array( WC_Order $order, array $tax_ids ): array {
$tax_rates = array();
$tax_items = $order->get_items( OrderItemType::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;
}