Last active
March 1, 2019 20:45
-
-
Save djrmom/4cd81102846033b063fa25bf6acad2de to your computer and use it in GitHub Desktop.
facetwp output woocommerce stars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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