[Experimental] Fix: get the correct min/max price for filtering (#43313)

This commit is contained in:
Tung Du 2024-01-05 17:19:33 +07:00 committed by GitHub
parent 009ff8707b
commit 37c94c7604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 12 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Filter Blocks: fix the filtering price to make it work with any number of decimal setting.

View File

@ -232,7 +232,7 @@ final class QueryFilters {
$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' ) );
$min_price_filter = intval( $wp_query->get( 'min_price' ) );
if ( $adjust_for_taxes ) {
$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $min_price_filter, 'min_price', '>=' );
@ -242,7 +242,7 @@ final class QueryFilters {
}
if ( $wp_query->get( 'max_price' ) ) {
$max_price_filter = $this->prepare_price_filter( $wp_query->get( 'max_price' ) );
$max_price_filter = intval( $wp_query->get( 'max_price' ) );
if ( $adjust_for_taxes ) {
$args['where'] .= $this->get_price_filter_query_for_displayed_taxes( $max_price_filter, 'max_price', '<=' );
@ -350,16 +350,6 @@ final class QueryFilters {
return $display !== $database;
}
/**
* Converts price filter from subunits to decimal.
*
* @param string|int $price_filter Raw price filter in subunit format.
* @return float Price filter in decimal format.
*/
private function prepare_price_filter( $price_filter ) {
return floatval( $price_filter / ( 10 ** wc_get_price_decimals() ) );
}
/**
* Adjusts a price filter based on a tax class and whether or not the amount includes or excludes taxes.
*