• Resolved murilo-reinert

    (@murilo-reinert)


    Hello,

    Can Relevanssi work with Woocommerce Price Filter Widget? It’s not order by price, it’s filter by price.

    My URL is as follow:
    /?min_price=1&max_price=3&s=shirt&post_type=product

    WP – 5.2.4
    Relevanssi – 4.3.4
    WC – 3.7.1
    Porto Theme

    Thank You

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter murilo-reinert

    (@murilo-reinert)

    To clarify, the Woocommerce Price Filter Widget does not work on a search page, the filter does not occur. Disabling Relevanssi solve the problem.

    Appreciate any help with this.

    Thank You

    Plugin Author Mikko Saari

    (@msaari)

    So, you see the price filter, but it doesn’t do anything? If that’s the case, add this to your theme functions.php:

    add_filter( 'relevanssi_hits_filter', 'rlv_price_filter' );
    function rlv_price_filter( $hits ) {
    	$min_price = isset( $_GET['min_price'] ) ? intval( $_GET['min_price'] ) : 0;
    	$max_price = isset( $_GET['max_price'] ) ? intval( $_GET['max_price'] ) : 0;
    	if ( ! $min_price || ! $max_price ) {
    		return $hits;
    	}
    	$filtered_products = array();
    	foreach( $hits[0] as $hit ) {
    		if ( 'product' !== $hit->post_type ) {
    			continue;
    		}
    		$product = wc_get_product( $hit->ID );
    		$price   = $product->get_price();
    		if ( $price >= $min_price && $price <= $max_price ) {
    			$filtered_products[] = $hit;
    		}
    	}
    	$hits[0] = $filtered_products;
    	return $hits;
    }

    Does that make the price filter work?

    Thread Starter murilo-reinert

    (@murilo-reinert)

    Worked perfect Mikko, thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce price filter widget – min_price – max_price’ is closed to new replies.