price filter
This commit is contained in:
parent
bd04e2eb26
commit
cac6a5dee7
|
@ -158,6 +158,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
||||||
* Tweak - Queries on report pages to replace get_posts to resolve issues on stores with a shed load of orders
|
* Tweak - Queries on report pages to replace get_posts to resolve issues on stores with a shed load of orders
|
||||||
* Tweak - Remove case sensitively from order tracking and force email lowercase on checkout
|
* Tweak - Remove case sensitively from order tracking and force email lowercase on checkout
|
||||||
* Tweak - woocommerce_update_variation_values trigger in JS
|
* Tweak - woocommerce_update_variation_values trigger in JS
|
||||||
|
* Tweak - Optimised price filter query (Thanks Lucas Stark)
|
||||||
* Fix - After tax coupons for categories
|
* Fix - After tax coupons for categories
|
||||||
* Fix - Multiple variation image upload
|
* Fix - Multiple variation image upload
|
||||||
* Fix - User email check for coupons
|
* Fix - User email check for coupons
|
||||||
|
|
|
@ -37,38 +37,37 @@ function woocommerce_price_filter_init() {
|
||||||
function woocommerce_price_filter($filtered_posts) {
|
function woocommerce_price_filter($filtered_posts) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (isset($_GET['max_price']) && isset($_GET['min_price'])) :
|
if ( isset( $_GET['max_price'] ) && isset( $_GET['min_price'] ) ) {
|
||||||
|
|
||||||
$matched_products = array();
|
$matched_products = array();
|
||||||
$low = floatval($_GET['min_price']);
|
$min = floatval( $_GET['min_price'] );
|
||||||
$high = floatval($_GET['max_price']);
|
$max = floatval( $_GET['max_price'] );
|
||||||
|
|
||||||
$matched_products_query = $wpdb->get_results(
|
$matched_products_query = $wpdb->get_results( $wpdb->prepare("
|
||||||
$wpdb->prepare(
|
SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts
|
||||||
"SELECT DISTINCT ID, post_parent, post_type FROM $wpdb->posts
|
|
||||||
INNER JOIN $wpdb->postmeta ON ID = post_id
|
INNER JOIN $wpdb->postmeta ON ID = post_id
|
||||||
WHERE (post_type='product' OR post_type='product_variation') AND post_status = 'publish' AND meta_key = %s AND meta_value BETWEEN %d AND %d", '_price', $low, $high), OBJECT_K);
|
WHERE post_type IN ( 'product', 'product_variation' ) AND post_status = 'publish' AND meta_key = %s AND meta_value BETWEEN %d AND %d
|
||||||
|
", '_price', $min, $max ), OBJECT_K );
|
||||||
|
|
||||||
|
if ( $matched_products_query ) {
|
||||||
if ($matched_products_query) :
|
foreach ( $matched_products_query as $product ) {
|
||||||
foreach ($matched_products_query as $product) :
|
if ( $product->post_type == 'product' )
|
||||||
if ($product->post_type == 'product')
|
|
||||||
$matched_products[] = $product->ID;
|
$matched_products[] = $product->ID;
|
||||||
if ($product->post_parent > 0 && !in_array($product->post_parent, $matched_products))
|
if ( $product->post_parent > 0 && ! in_array( $product->post_parent, $matched_products ) )
|
||||||
$matched_products[] = $product->post_parent;
|
$matched_products[] = $product->post_parent;
|
||||||
endforeach;
|
}
|
||||||
endif;
|
}
|
||||||
|
|
||||||
// Filter the id's
|
// Filter the id's
|
||||||
if (sizeof($filtered_posts) == 0) :
|
if ( sizeof( $filtered_posts ) == 0) {
|
||||||
$filtered_posts = $matched_products;
|
$filtered_posts = $matched_products;
|
||||||
$filtered_posts[] = 0;
|
$filtered_posts[] = 0;
|
||||||
else :
|
} else {
|
||||||
$filtered_posts = array_intersect($filtered_posts, $matched_products);
|
$filtered_posts = array_intersect( $filtered_posts, $matched_products );
|
||||||
$filtered_posts[] = 0;
|
$filtered_posts[] = 0;
|
||||||
endif;
|
}
|
||||||
|
|
||||||
endif;
|
}
|
||||||
|
|
||||||
return (array) $filtered_posts;
|
return (array) $filtered_posts;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue