Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active March 1, 2019 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/4cd81102846033b063fa25bf6acad2de to your computer and use it in GitHub Desktop.
Save djrmom/4cd81102846033b063fa25bf6acad2de to your computer and use it in GitHub Desktop.
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment