FacetWP – Integrate with “WPJM – Products” plugin to index WooCommerce prices

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

// Also change the data source to “Post Type”

function fwp_index_wpjm_product_prices( $params, $class ) {
if ( ‘price_range’ == $params[‘facet_name’] ) {
$product_ids = get_post_meta( $params[‘post_id’], ‘_products’, true );
foreach ( $product_ids as $id ) {
$product = wc_get_product( $id );
$price = $product->get_price();
$params[‘facet_value’] = $price;
$params[‘facet_display_value’] = $price;
$class->insert( $params );
}
return false; // prevent default indexing
}
return $params;
}
add_filter( ‘facetwp_index_row’, ‘fwp_index_wpjm_product_prices’, 10, 2 );

{{/gist}}