[Resolved] Woocommerce Product Review Stars

Home Forums Support [Resolved] Woocommerce Product Review Stars

Home Forums Support Woocommerce Product Review Stars

  • This topic has 1 reply, 2 voices, and was last updated 7 years ago by Tom.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #305673
    David
    Staff
    Customer Support

    I thought the GP woocommerce users might find this useful. If like me you like everything to align then the annoyance with the products text position that do or dont have review stars is a major sore point. Found a simple snippet to alleviate the problem by showing empty stars with no reviews:

    
    // Woocommerce rating stars always
    	add_filter('woocommerce_product_get_rating_html', 'your_get_rating_html', 10, 2);
    
    	function your_get_rating_html($rating_html, $rating) {
      	if ( $rating > 0 ) {
        	$title = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating );
      	} else {
        	$title = 'Not yet rated';
        	$rating = 0;
      	}
    
      	$rating_html  = '<div class="star-rating" title="' . $title . '">';
      	$rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . __( 'out of 5', 'woocommerce' ) . '</span>';
      	$rating_html .= '</div>';
      	return $rating_html;
    	}
    

    Found here for kudos where its deserved:

    https://wordpress.org/support/topic/how-to-display-empty-star-ratingsnot-rated-yet/

    I must say GP theme is great but the support is even better. Learnt a lot from these forums and refreshed a few memories from my old days coding.

    #305710
    Tom
    Lead Developer
    Lead Developer

    Thanks for sharing! Might add that option to the WooCommerce add-on I’m working on 🙂

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.