WC_REST_Products_Controller::add_search_criteria_to_wp_query_where
Add a where clause for matching the SKU field.
Method of the class: WC_REST_Products_Controller{}
No Hooks.
Returns
String.
Usage
$WC_REST_Products_Controller = new WC_REST_Products_Controller(); $WC_REST_Products_Controller->add_search_criteria_to_wp_query_where( $where );
- $where(string) (required)
- Where clause used to search posts.
WC_REST_Products_Controller::add_search_criteria_to_wp_query_where() WC REST Products Controller::add search criteria to wp query where code WC 10.3.6
public function add_search_criteria_to_wp_query_where( $where ) {
global $wpdb;
if ( $this->search_fields_tokens ) {
$where .= $this->build_dynamic_search_clauses(
$this->search_fields_tokens['tokens'],
$this->search_fields_tokens['fields']
);
} elseif ( $this->search_name_or_sku_tokens ) {
$searchable_fields = wc_product_sku_enabled() ? array( 'name', 'sku' ) : array( 'name' );
$where .= $this->build_dynamic_search_clauses(
$this->search_name_or_sku_tokens,
$searchable_fields
);
} elseif ( ! empty( $this->search_sku_arg_value ) ) {
$like_search = '%' . $wpdb->esc_like( $this->search_sku_arg_value ) . '%';
$where .= ' AND ' . $wpdb->prepare( '(wc_product_meta_lookup.sku LIKE %s)', $like_search );
}
return $where;
}