WC_REST_Products_V4_Controller::add_search_criteria_to_wp_query_join
Join wc_product_meta_lookup table when SKU search query is present.
Method of the class: WC_REST_Products_V4_Controller{}
No Hooks.
Returns
String.
Usage
$WC_REST_Products_V4_Controller = new WC_REST_Products_V4_Controller(); $WC_REST_Products_V4_Controller->add_search_criteria_to_wp_query_join( $join );
- $join(string) (required)
- Join clause used to search posts.
WC_REST_Products_V4_Controller::add_search_criteria_to_wp_query_join() WC REST Products V4 Controller::add search criteria to wp query join code WC 10.3.6
woocommerce/includes/rest-api/Controllers/Version4/Products/class-wc-rest-products-v4-controller.php
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;
}