Home Forums WoodMart support forum Problem with Filter by price slider – it doesn’t change on filter by attributes Reply To: Problem with Filter by price slider – it doesn’t change on filter by attributes

#561483

media-3572
Participant

I’m posting this to help others who are experiencing the same problem as me.

I think I was able to fix the problem by replacing the existing code of function woodmart_get_filtered_price_new() in woodmart\inc\woodmart\inc\integrations\woocommerce\functions.php

with this one

if ( ! function_exists( ‘woodmart_get_filtered_price_new’ ) ) {
function woodmart_get_filtered_price_new() {
global $wpdb;

$args = WC()->query->get_main_query()->query_vars;
$tax_query = isset( $args[‘tax_query’] ) ? $args[‘tax_query’] : array();
$meta_query = isset( $args[‘meta_query’] ) ? $args[‘meta_query’] : array();

if ( ! is_post_type_archive( ‘product’ ) && ! empty( $args[‘taxonomy’] ) && ! empty( $args[‘term’] ) ) {
$tax_query[] = WC()->query->get_main_tax_query();
}

foreach ( $meta_query + $tax_query as $key => $query ) {
if ( ! empty( $query[‘price_filter’] ) || ! empty( $query[‘rating_filter’] ) ) {
unset( $meta_query[ $key ] );
}
}

$meta_query = new WP_Meta_Query( $meta_query );
$tax_query = new WP_Tax_Query( $tax_query );
$search = WC_Query::get_main_search_query_sql();

$meta_query_sql = $meta_query->get_sql( ‘post’, $wpdb->posts, ‘ID’ );
$tax_query_sql = $tax_query->get_sql( $wpdb->posts, ‘ID’ );
$search_query_sql = $search ? ‘ AND ‘ . $search : ”;

$sql = ”
SELECT min( min_price ) as min_price, MAX( max_price ) as max_price
FROM {$wpdb->wc_product_meta_lookup}
WHERE product_id IN (
SELECT ID FROM {$wpdb->posts}
” . $tax_query_sql[‘join’] . $meta_query_sql[‘join’] . ”
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’
” . $tax_query_sql[‘where’] . $meta_query_sql[‘where’] . $search_query_sql . ‘
)’;

$sql = apply_filters( ‘woocommerce_price_filter_sql’, $sql, $meta_query_sql, $tax_query_sql );

return $wpdb->get_row( $sql ); // WPCS: unprepared SQL ok.
}
}

And it worked

I do not know how this will behave when “Use the product attributes lookup table for catalog filtering” is enabled in WooCommerce -> Settings -> Products -> Advanced, but i do not care. When considering that there is an issue with the price filter when “Use the product attributes lookup table for catalog filtering” is enabled, I prefer to leave it as it is for now.

Actually you have a problem right now with the “FILTER button” in the “Price Filter” add-on for wpbakery in 7.5.1 – it doesn’t work – just refreshes the page and it is not making any filtering – in the url does’t appear also. I mean this doesn’t appear – something like this “?min_price=100&max_price=1826”

I will stick with previous version where “FILTER button” and the code which I am providing and I already replaced – also works

Regards

You can close this ticket