Automattic\WooCommerce\Internal\Tax
TaxRateDataStore::get_rate_objects_for_ids
Fetch multiple tax rate rows in a single query, keyed by tax_rate_id.
Метод класса: TaxRateDataStore{}
Хуков нет.
Возвращает
array<int,object>.
Использование
$TaxRateDataStore = new TaxRateDataStore(); $TaxRateDataStore->get_rate_objects_for_ids( $ids ): array;
- $ids(int[]) (обязательный)
- Tax rate IDs to fetch.
Список изменений
| С версии 11.0.0 | Введена. |
Код TaxRateDataStore::get_rate_objects_for_ids() TaxRateDataStore::get rate objects for ids WC 11.2.2
public function get_rate_objects_for_ids( array $ids ): array {
global $wpdb;
$ids = array_filter( array_map( 'absint', array_unique( $ids ) ) );
$uncached_ids = array_diff( $ids, array_keys( $this->rate_objects_cache ) );
if ( ! empty( $uncached_ids ) ) {
$list = implode( ', ', $uncached_ids );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$rows = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id IN ( $list )" );
foreach ( $rows as $row ) {
$this->rate_objects_cache[ (int) $row->tax_rate_id ] = $row;
}
}
$result = array();
foreach ( $ids as $id ) {
if ( isset( $this->rate_objects_cache[ $id ] ) ) {
$result[ $id ] = $this->rate_objects_cache[ $id ];
}
}
return $result;
}