From 8345f67f6c89233be1bf95c3014748dcb328b2b5 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 22 Feb 2016 13:23:22 +0000 Subject: [PATCH] Tweak price filter + code comments #10371 --- includes/class-wc-query.php | 19 +++++++++-------- .../widgets/class-wc-widget-price-filter.php | 21 ++++++++++--------- .../widgets/class-wc-widget-rating-filter.php | 1 + 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index 1a1e368ada8..1645af43adf 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -517,21 +517,22 @@ class WC_Query { $min = isset( $_GET['min_price'] ) ? floatval( $_GET['min_price'] ) : 0; $max = isset( $_GET['max_price'] ) ? floatval( $_GET['max_price'] ) : 9999999999; - // If displaying prices in the shop including taxes, but prices don't include taxes.. + /** + * Adjust if the store taxes are not displayed how they are stored. + * Max is left alone because the filter was already increased. + * Kicks in when prices excluding tax are displayed including tax. + */ if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) { $tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() ); + $class_min = $min; foreach ( $tax_classes as $tax_class ) { - $tax_rates = WC_Tax::get_rates( $tax_class ); - $class_min = $min - WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $min, $tax_rates ) ); - $class_max = $max - WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $max, $tax_rates ) ); - if ( $class_min < $min ) { - $min = $class_min; - } - if ( $class_max > $max ) { - $max = $class_max; + if ( $tax_rates = WC_Tax::get_rates( $tax_class ) ) { + $class_min = $min - WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $min, $tax_rates ) ); } } + + $min = $class_min; } return array( diff --git a/includes/widgets/class-wc-widget-price-filter.php b/includes/widgets/class-wc-widget-price-filter.php index a47e96c63bc..fb70ebdf3dd 100644 --- a/includes/widgets/class-wc-widget-price-filter.php +++ b/includes/widgets/class-wc-widget-price-filter.php @@ -118,27 +118,28 @@ class WC_Widget_Price_Filter extends WC_Widget { $this->widget_start( $args, $instance ); - if ( '' == get_option( 'permalink_structure' ) ) { + if ( '' === get_option( 'permalink_structure' ) ) { $form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ); } else { $form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) ); } - // Adjust min and max if the store taxes are not displayed how they are stored + /** + * Adjust max if the store taxes are not displayed how they are stored. + * Min is left alone because the product may not be taxable. + * Kicks in when prices excluding tax are displayed including tax. + */ if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) { $tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() ); + $class_max = $max; foreach ( $tax_classes as $tax_class ) { - $tax_rates = WC_Tax::get_rates( $tax_class ); - $class_min = $min + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $min, $tax_rates ) ); - $class_max = $max + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max, $tax_rates ) ); - if ( $class_min < $min ) { - $min = $class_min; - } - if ( $class_max > $max ) { - $max = $class_max; + if ( $tax_rates = WC_Tax::get_rates( $tax_class ) ) { + $class_max = $max + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max, $tax_rates ) ); } } + + $max = $class_max; } echo '
diff --git a/includes/widgets/class-wc-widget-rating-filter.php b/includes/widgets/class-wc-widget-rating-filter.php index f66bb0f63a4..38e6edb0e0c 100644 --- a/includes/widgets/class-wc-widget-rating-filter.php +++ b/includes/widgets/class-wc-widget-rating-filter.php @@ -149,6 +149,7 @@ class WC_Widget_Rating_Filter extends WC_Widget { ob_start(); + $found = false; $min_rating = isset( $_GET['min_rating'] ) ? absint( $_GET['min_rating'] ) : ''; $this->widget_start( $args, $instance );