-
-
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
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 // 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