Automattic\WooCommerce\Admin\API
Products::add_wp_query_filter()
Add in conditional search filters for products.
Метод класса: Products{}
Хуков нет.
Возвращает
Строку
.
Использование
$result = Products::add_wp_query_filter( $where, $wp_query );
- $where(строка) (обязательный)
- Where clause used to search posts.
- $wp_query(объект) (обязательный)
- WP_Query object.
Код Products::add_wp_query_filter() Products::add wp query filter WC 9.2.3
public static function add_wp_query_filter( $where, $wp_query ) { global $wpdb; $search = $wp_query->get( 'search' ); if ( $search ) { $title_like = '%' . $wpdb->esc_like( $search ) . '%'; $where .= $wpdb->prepare( " AND ({$wpdb->posts}.post_title LIKE %s", $title_like ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $where .= wc_product_sku_enabled() ? $wpdb->prepare( ' OR wc_product_meta_lookup.sku LIKE %s)', $search ) : ')'; } if ( $wp_query->get( 'low_in_stock' ) ) { $low_stock_amount = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); $where .= " AND wc_product_meta_lookup.stock_quantity IS NOT NULL AND wc_product_meta_lookup.stock_status IN('instock','outofstock') AND ( ( low_stock_amount_meta.meta_value > '' AND wc_product_meta_lookup.stock_quantity <= CAST(low_stock_amount_meta.meta_value AS SIGNED) ) OR ( ( low_stock_amount_meta.meta_value IS NULL OR low_stock_amount_meta.meta_value <= '' ) AND wc_product_meta_lookup.stock_quantity <= {$low_stock_amount} ) )"; } return $where; }