facetwp output woocommerce stars

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php

/** outputs woocommerce rating as stars in layout builder **/
add_filter( ‘facetwp_builder_item_value’, function( $value, $item ) {
if ( ‘woo/average_rating’ == $item[‘source’] ) { // replace some_field with your item source

$product = wc_get_product( get_the_ID() );

$rating_count = $product->get_rating_count();
$average = $product->get_average_rating();

$value = ‘<div class=”woocommerce-product-rating”>’ . wc_get_rating_html( $average, $rating_count ) . ‘</div>’;
}
return $value;
}, 10, 2 );
{{/gist}}