Automattic\WooCommerce\Blocks
QueryFilters::get_filtered_price()
Get price data for current products.
Method of the class: QueryFilters{}
No Hooks.
Return
Object
.
Usage
$QueryFilters = new QueryFilters(); $QueryFilters->get_filtered_price( $query_vars );
- $query_vars(array) (required)
- The WP_Query arguments.
QueryFilters::get_filtered_price() QueryFilters::get filtered price code WC 9.4.2
public function get_filtered_price( $query_vars ) { global $wpdb; add_filter( 'posts_clauses', array( $this, 'add_query_clauses' ), 10, 2 ); add_filter( 'posts_pre_query', '__return_empty_array' ); $query_vars['no_found_rows'] = true; $query_vars['posts_per_page'] = -1; $query_vars['fields'] = 'ids'; $query = new \WP_Query(); $query->query( $query_vars ); $product_query_sql = $query->request; remove_filter( 'posts_clauses', array( $this, 'add_query_clauses' ), 10 ); remove_filter( 'posts_pre_query', '__return_empty_array' ); $price_filter_sql = " SELECT min( min_price ) as min_price, MAX( max_price ) as max_price FROM {$wpdb->wc_product_meta_lookup} WHERE product_id IN ( {$product_query_sql} ) "; return $wpdb->get_row( $price_filter_sql ); // phpcs:ignore }