Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show 0 stars and a call to action if a product has no reviews - for use with Product Reviews Pro
<?php // only use if needed
add_action ( 'woocommerce_before_template_part', function( $template_name ) {
global $product;
if ( $product instanceof WC_Product ) {
$rating_count = $product->get_rating_count();
if ( 'single-product/rating.php' == $template_name && 0 === $rating_count ) {
$label = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), 0 );
$html = '<div class="star-rating" role="img" aria-label="' . esc_attr( $label ) . '">' . wc_get_star_rating_html( 0 ) . '</div>';
echo $html . '<a href="#tab-title-reviews">Leave a review</a>';
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment