WC_Widget_Price_Filter::get_filtered_price()protectedWC 1.0

Get filtered min price for current products.

Method of the class: WC_Widget_Price_Filter{}

Return

Int.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_filtered_price();

WC_Widget_Price_Filter::get_filtered_price() code WC 8.7.0

protected function get_filtered_price() {
	global $wpdb;

	$args       = WC()->query->get_main_query()->query_vars;
	$tax_query  = isset( $args['tax_query'] ) ? $args['tax_query'] : array();
	$meta_query = isset( $args['meta_query'] ) ? $args['meta_query'] : array();

	if ( ! is_post_type_archive( 'product' ) && ! empty( $args['taxonomy'] ) && ! empty( $args['term'] ) ) {
		$tax_query[] = WC()->query->get_main_tax_query();
	}

	foreach ( $meta_query + $tax_query as $key => $query ) {
		if ( ! empty( $query['price_filter'] ) || ! empty( $query['rating_filter'] ) ) {
			unset( $meta_query[ $key ] );
		}
	}

	$meta_query = new WP_Meta_Query( $meta_query );
	$tax_query  = new WP_Tax_Query( $tax_query );
	$search     = WC_Query::get_main_search_query_sql();

	$meta_query_sql   = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
	$tax_query_sql    = $tax_query->get_sql( $wpdb->posts, 'ID' );
	$search_query_sql = $search ? ' AND ' . $search : '';

	$sql = "
		SELECT min( min_price ) as min_price, MAX( max_price ) as max_price
		FROM {$wpdb->wc_product_meta_lookup}
		WHERE product_id IN (
			SELECT ID FROM {$wpdb->posts}
			" . $tax_query_sql['join'] . $meta_query_sql['join'] . "
			WHERE {$wpdb->posts}.post_type IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_post_type', array( 'product' ) ) ) ) . "')
			AND {$wpdb->posts}.post_status = 'publish'
			" . $tax_query_sql['where'] . $meta_query_sql['where'] . $search_query_sql . '
		)';

	$sql = apply_filters( 'woocommerce_price_filter_sql', $sql, $meta_query_sql, $tax_query_sql );

	return $wpdb->get_row( $sql ); // WPCS: unprepared SQL ok.
}