• Hi, how do I set 5 star default ratings if the products have no ratings and review yet? (Like in DaVinci Woo theme) Please help. Thanks in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter chanelparcs

    (@chanelparcs)

    Got it!

    // Always display rating stars even without reviews – Single Product Page

    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’, 6 );
    }

    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();
    $count_html = ‘<div class=”count-rating”>’ . array_sum($product->get_rating_counts()) . ‘</div>’;
    ?>
    <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() ) : ?>(<?php printf( _n( ‘%s customer review’, ‘%s customer reviews’, $review_count, ‘woocommerce’ ), ‘<span class=”count”>’ . esc_html( $review_count ) . ‘</span>’ ); ?>)<?php endif ?>
    </div></div>
    <?php
    } else {

    ?>
    <div class=”woocommerce-product-rating”>
    <div class=”container-rating”><div class=”star-rating”>
    <?php echo wc_get_rating_html( 5, 5 ); ?>
    </div>

    </div></div>
    <?php

    }
    }

    // Always display rating stars even without reviews – Category Page, Archive Page, Product Gallery

    function filter_woocommerce_product_get_rating_html( $rating_html, $rating, $count ) {
    $rating_html = ‘<div class=”star-rating”>’;
    $rating_html .= wc_get_star_rating_html( 5, 5 );
    $rating_html .= ‘</div>’;

    return $rating_html;
    };
    add_filter( ‘woocommerce_product_get_rating_html’, ‘filter_woocommerce_product_get_rating_html’, 10, 3 );

Viewing 1 replies (of 1 total)
  • The topic ‘Default 5 Star Ratings’ is closed to new replies.