Tweak price filter + code comments

#10371
This commit is contained in:
Mike Jolley 2016-02-22 13:23:22 +00:00
parent f52b018279
commit 8345f67f6c
3 changed files with 22 additions and 19 deletions

View File

@ -517,21 +517,22 @@ class WC_Query {
$min = isset( $_GET['min_price'] ) ? floatval( $_GET['min_price'] ) : 0; $min = isset( $_GET['min_price'] ) ? floatval( $_GET['min_price'] ) : 0;
$max = isset( $_GET['max_price'] ) ? floatval( $_GET['max_price'] ) : 9999999999; $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() ) { 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() ); $tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
$class_min = $min;
foreach ( $tax_classes as $tax_class ) { foreach ( $tax_classes as $tax_class ) {
$tax_rates = WC_Tax::get_rates( $tax_class ); if ( $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_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_inclusive_tax( $max, $tax_rates ) );
if ( $class_min < $min ) {
$min = $class_min;
}
if ( $class_max > $max ) {
$max = $class_max;
} }
} }
$min = $class_min;
} }
return array( return array(

View File

@ -118,27 +118,28 @@ class WC_Widget_Price_Filter extends WC_Widget {
$this->widget_start( $args, $instance ); $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 ) ) ); $form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
} else { } else {
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) ); $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() ) { 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() ); $tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
$class_max = $max;
foreach ( $tax_classes as $tax_class ) { foreach ( $tax_classes as $tax_class ) {
$tax_rates = WC_Tax::get_rates( $tax_class ); 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 ) ); $class_max = $max + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max, $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;
} }
} }
$max = $class_max;
} }
echo '<form method="get" action="' . esc_url( $form_action ) . '"> echo '<form method="get" action="' . esc_url( $form_action ) . '">

View File

@ -149,6 +149,7 @@ class WC_Widget_Rating_Filter extends WC_Widget {
ob_start(); ob_start();
$found = false;
$min_rating = isset( $_GET['min_rating'] ) ? absint( $_GET['min_rating'] ) : ''; $min_rating = isset( $_GET['min_rating'] ) ? absint( $_GET['min_rating'] ) : '';
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );