jenny-r
2/28/2019 - 10:29 PM

facetwp output woocommerce stars

facetwp output woocommerce stars

<?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 );