Automattic\WooCommerce\StoreApi\Utilities

ProductQuery::add_price_filter_clauses()protectedWC 1.0

Add in conditional price filters.

Method of the class: ProductQuery{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->add_price_filter_clauses( $args, $wp_query );
$args(array) (required)
Query args.
$wp_query(\WC_Query) (required)
WC_Query object.

ProductQuery::add_price_filter_clauses() code WC 9.3.3

protected function add_price_filter_clauses( $args, $wp_query ) {
	global $wpdb;

	$adjust_for_taxes = $this->adjust_price_filters_for_displayed_taxes();
	$args['join']     = $this->append_product_sorting_table_join( $args['join'] );

	if ( $wp_query->get( 'min_price' ) ) {
		$min_price_filter = $this->prepare_price_filter( $wp_query->get( 'min_price' ) );

		if ( $adjust_for_taxes ) {
			$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $min_price_filter, 'max_price', '>=' );
		} else {
			$args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.max_price >= %f ', $min_price_filter );
		}
	}

	if ( $wp_query->get( 'max_price' ) ) {
		$max_price_filter = $this->prepare_price_filter( $wp_query->get( 'max_price' ) );

		if ( $adjust_for_taxes ) {
			$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $max_price_filter, 'min_price', '<=' );
		} else {
			$args['where'] .= $wpdb->prepare( ' AND wc_product_meta_lookup.min_price <= %f ', $max_price_filter );
		}
	}

	return $args;
}