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
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?
Worked perfect Mikko, thank you.