Skip to content

Instantly share code, notes, and snippets.

@juliebugmtl
Created August 9, 2021 01:25
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 juliebugmtl/b223a68a66cff3681d11e283f659ea99 to your computer and use it in GitHub Desktop.
Save juliebugmtl/b223a68a66cff3681d11e283f659ea99 to your computer and use it in GitHub Desktop.
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