Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableSearchQuery::generate_join_for_search_filter
Generate JOIN clause for a given search filter. Right now we only have the products filter that actually does a JOIN, but in the future we may add more -- for example, custom order fields, payment tokens, and so on. This function makes it easier to add more filters in the future.
If a search filter needs a JOIN, it will also need a WHERE clause.
Method of the class: OrdersTableSearchQuery{}
Hooks from the method
Returns
string. JOIN clause.
Usage
// private - for code of main (parent) class only $result = $this->generate_join_for_search_filter( $search_filter ): string;
- $search_filter(string) (required)
- Name of the search filter.
OrdersTableSearchQuery::generate_join_for_search_filter() OrdersTableSearchQuery::generate join for search filter code WC 11.1.2
private function generate_join_for_search_filter( $search_filter ): string {
$join = '';
if ( 'products' === $search_filter ) {
$join = $this->maybe_get_join_for_products();
}
if ( 'customers' === $search_filter ) {
$join = $this->maybe_get_join_for_customers();
}
/**
* Filter to support adding a custom order search filter.
* Provide a JOIN clause for a new search filter. This should be used along with `woocommerce_hpos_admin_search_filters`
* to declare a new custom filter, and `woocommerce_hpos_generate_where_for_search_filter` to generate the WHERE
* clause.
*
* Hardcoded JOINS (products) cannot be modified using this filter for consistency.
*
* @since 8.9.0
*
* @param string $join The JOIN clause.
* @param string $search_term The search term.
* @param string $search_filter The search filter. Use this to bail early if this is not filter you are interested in.
* @param OrdersTableQuery $query The order query object.
*/
return apply_filters(
'woocommerce_hpos_generate_join_for_search_filter',
$join,
$this->search_term,
$search_filter,
$this->query
);
}