S
S
Sergey Shkurikhin2020-10-24 02:43:29
WooCommerce
Sergey Shkurikhin, 2020-10-24 02:43:29

How to display a zero rating - stars, on the product page in a short description?

How to display a zero rating on the product page ? I have already displayed in the catalog, but on the product page itself, the stars are only if there are reviews. How can I make empty stars show up there as well..?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Khmelevsky, 2020-11-03
@shkyrikhin99

add_action('woocommerce_single_product_summary', 'change_single_product_ratings', 2 );
function change_single_product_ratings(){
    remove_action('woocommerce_single_product_summary','woocommerce_template_single_rating', 10 );
    add_action('woocommerce_single_product_summary','wc_single_product_ratings', 5 );
}

function wc_single_product_ratings(){
    global $product;

    $rating_count = $product->get_rating_count();
  
    if ( $rating_count >= 0 ) {
        $review_count = $product->get_review_count();
        $average      = $product->get_average_rating();
        ?>
        <div class="woocommerce-product-rating">
            <div class="container-rating"><div class="star-rating">
            <?php echo wc_get_rating_html( $average, $rating_count ); ?>
            </div>
            <?php if ( comments_open() ) : ?><a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?></div>
    </div>
        <?php
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question