• 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)
  • Mirko P.

    (@rainfallnixfig)

    Hi @dharabt,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thanks.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    There hasn’t been much activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to find a solution to this and the above resources for developers were helpful. If you have questions on core WooCommerce please feel free to open a new topic.

    Thanks.

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.