Remove Filter “price_filter_post_clauses” is not working in version 5.6.0
-
Hey,
I need to Product Price Filer by region of the customer so I need to custom filter with Custom meta fields. In which REmove filter with
remove_filter('posts_clauses', [WC()->query, 'price_filter_post_clauses']);
but after update new version it is not possible to do it.Please look at below code:
add_action('woocommerce_product_query', 'min_max_price_handler', 50); function min_max_price_handler($q) { global $wpdb, $wp_query; $price = 'price_default'; // Remove default Woocommerce min/max price request handler remove_filter('posts_clauses', [WC()->query, 'price_filter_post_clauses']); if (! $wp_query->is_main_query() || ( ! isset($_GET['max_price']) && ! isset($_GET['min_price']))) { return; } $current_min_price = isset($_GET['min_price']) ? floatval(wp_unslash($_GET['min_price'])) : 0; $current_max_price = isset($_GET['max_price']) ? floatval(wp_unslash($_GET['max_price'])) : PHP_INT_MAX; $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => $price, 'value' => array($current_min_price, $current_max_price), 'compare' => 'BETWEEN', ), ), ); $query = new WP_Query( $args ); $results = []; if($query->have_posts()){ while($query->have_posts()){ $query->the_post(); $results[] = get_the_ID(); } } wp_reset_postdata(); if (is_array($results)) { $q->set('post__in', $results); } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Remove Filter “price_filter_post_clauses” is not working in version 5.6.0’ is closed to new replies.