Min/Max Modifications
CAST min/max as decimal. Otherwise, a max of 59.99 will return 59 instead of 60 - so the product will be missed when using the filter. Added filter on post_type so I can add product_variation for compatibility with one of my plugins.
This commit is contained in:
parent
7172429244
commit
b2bf294e03
|
@ -153,9 +153,9 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
||||||
$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
|
$meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' );
|
||||||
$tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
|
$tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' );
|
||||||
|
|
||||||
$sql = "SELECT min( CAST( price_meta.meta_value AS DECIMAL ) ) as min_price, max( CAST( price_meta.meta_value AS DECIMAL ) ) as max_price FROM {$wpdb->posts} ";
|
$sql = "SELECT min( CAST( price_meta.meta_value AS DECIMAL(2) ) ) as min_price, max( CAST( price_meta.meta_value AS DECIMAL(2) ) ) as max_price FROM {$wpdb->posts} ";
|
||||||
$sql .= " LEFT JOIN {$wpdb->postmeta} as price_meta ON {$wpdb->posts}.ID = price_meta.post_id " . $tax_query_sql['join'] . $meta_query_sql['join'];
|
$sql .= " LEFT JOIN {$wpdb->postmeta} as price_meta ON {$wpdb->posts}.ID = price_meta.post_id " . $tax_query_sql['join'] . $meta_query_sql['join'];
|
||||||
$sql .= " WHERE {$wpdb->posts}.post_type = 'product'
|
$sql .= " 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'
|
AND {$wpdb->posts}.post_status = 'publish'
|
||||||
AND price_meta.meta_key IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) ) . "')
|
AND price_meta.meta_key IN ('" . implode( "','", array_map( 'esc_sql', apply_filters( 'woocommerce_price_filter_meta_keys', array( '_price' ) ) ) ) . "')
|
||||||
AND price_meta.meta_value > '' ";
|
AND price_meta.meta_value > '' ";
|
||||||
|
|
Loading…
Reference in New Issue