Automattic\WooCommerce\Internal\Admin\Reports
ProductSearchQuery::get_id_condition
Returns the condition restricting a report to a set of products.
A search resolves to a subquery, the categories and products filters to an ID list. The subquery already covers those filters, since it is built restricted to the same IDs.
Not a data store method: both products data stores need it and one extends the other, so it would become part of what extensions inherit.
Method of the class: ProductSearchQuery{}
No Hooks.
Returns
string. SQL condition, or an empty string when the report is not restricted.
Usage
$result = ProductSearchQuery::get_id_condition( $column, $search_subquery, $included_products ): string;
- $column(string) (required)
- Product ID column to compare, qualified with its table name.
- $search_subquery(string) (required)
- Statement the
searchargument resolves to, fromget_ids_subquery(). Empty when the report carries no search. - $included_products(array) (required)
- Product IDs the
categoriesandproductsfilters resolve to.
Changelog
| Since 11.2.0 | Introduced. |
ProductSearchQuery::get_id_condition() ProductSearchQuery::get id condition code WC 11.3.0
public static function get_id_condition( string $column, string $search_subquery, array $included_products ): string {
if ( '' !== $search_subquery ) {
return "{$column} IN ( {$search_subquery} )";
}
$id_list = implode( ',', $included_products );
return $id_list ? "{$column} IN ( {$id_list} )" : '';
}