Automattic\WooCommerce\Internal\RestApi\Routes\V4\Products
Controller::add_search_criteria_to_wp_query_join
Join wc_product_meta_lookup table when SKU search query is present.
Method of the class: Controller{}
No Hooks.
Returns
String.
Usage
$Controller = new Controller(); $Controller->add_search_criteria_to_wp_query_join( $join );
- $join(string) (required)
- Join clause used to search posts.
Controller::add_search_criteria_to_wp_query_join() Controller::add search criteria to wp query join code WC 10.4.3
public function add_search_criteria_to_wp_query_join( $join ) {
// Check if already joined to avoid duplicate joins.
if ( strstr( $join, 'wc_product_meta_lookup' ) ) {
return $join;
}
// Only join if we need meta table search.
if ( ! $this->search_fields_tokens &&
! $this->search_sku_arg_value &&
! ( $this->search_name_or_sku_tokens && wc_product_sku_enabled() ) ) {
return $join;
}
global $wpdb;
$join .= " LEFT JOIN $wpdb->wc_product_meta_lookup wc_product_meta_lookup
ON $wpdb->posts.ID = wc_product_meta_lookup.product_id ";
return $join;
}