Automattic\WooCommerce\Admin\API\Reports\Taxes
DataStore::get_location_filter_subquery
The location filter of a report query, as a condition on the lookup table alone.
The tax code lives on the tax order item, which the stats queries do not join: joining it would repeat a summed row for every line of the order sharing its rate, so an EXISTS check reads the code instead. A row keyed by its tax line reads that one item by its primary key. Only a legacy row at the zero default has to search the order's tax items for its rate.
Метод класса: DataStore{}
Хуков нет.
Возвращает
string. SQL condition, or an empty string when the query carries no location filter.
Использование
$result = DataStore::get_location_filter_subquery( $query_args ): string;
- $query_args(массив) (обязательный)
- Query arguments supplied by the user.
Список изменений
| С версии 11.3.0 | Введена. |
Код DataStore::get_location_filter_subquery() DataStore::get location filter subquery WC 11.3.0
public static function get_location_filter_subquery( array $query_args ): string {
global $wpdb;
$condition = self::get_location_filter_condition( $query_args );
if ( '' === $condition ) {
return '';
}
$table_name = self::get_db_table_name();
$items = $wpdb->prefix . 'woocommerce_order_items';
$item_meta = $wpdb->prefix . 'woocommerce_order_itemmeta';
$tax_type = OrderItemType::TAX;
return "( ( {$table_name}.order_item_id > 0 AND EXISTS ( SELECT 1 FROM {$items}
WHERE {$items}.order_item_id = {$table_name}.order_item_id
AND {$condition} ) )
OR ( {$table_name}.order_item_id = 0 AND EXISTS ( SELECT 1 FROM {$items}
JOIN {$item_meta} location_rate_id ON location_rate_id.order_item_id = {$items}.order_item_id AND location_rate_id.meta_key = 'rate_id'
WHERE {$items}.order_id = {$table_name}.order_id
AND {$items}.order_item_type = '{$tax_type}'
AND location_rate_id.meta_value = {$table_name}.tax_rate_id
AND {$condition} ) ) )";
}