Automattic\WooCommerce\Admin\API
ProductVariations::add_wp_query_filter()
Add in conditional search filters for variations.
Method of the class: ProductVariations{}
No Hooks.
Return
String
.
Usage
$result = ProductVariations::add_wp_query_filter( $where, $wp_query );
- $where(string) (required)
- Where clause used to search posts.
- $wp_query(object) (required)
- WP_Query object.
ProductVariations::add_wp_query_filter() ProductVariations::add wp query filter code WC 9.3.3
public static function add_wp_query_filter( $where, $wp_query ) { global $wpdb; $search = $wp_query->get( 'search' ); if ( $search ) { $like = '%' . $wpdb->esc_like( $search ) . '%'; $conditions = array( $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like ), // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->prepare( 'attr_search_meta.meta_value LIKE %s', $like ), // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared ); if ( wc_product_sku_enabled() ) { $conditions[] = $wpdb->prepare( 'wc_product_meta_lookup.sku LIKE %s', $like ); } $where .= ' AND (' . implode( ' OR ', $conditions ) . ')'; } return $where; }