• Hi,

    I want to display review count next to star rating like ★★★★★(count)

    Please let me know how do i that

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You can use the below code to get the review count

    <?php $comments_count = wp_count_comments( post_id ); ?>
    <?php echo $comments_count->total_comments; ?>

    Woocommerce already displays reviews count next to star rating in single product page. But on shop and archives page it displays only star rating. Follow the below steps to display star rating count even on shop and archives pages.

    Step 1) Create a new folder in your theme’s root and name it ‘woocommerce’

    Step 2) Create a new folder in the newly created ‘woocommerce’ folder and name it ‘loop’

    Step 3) Add ‘rating.php’ file to the newly created ‘loop’ folder

    Now your directory would look something like this

    /public_html/wp-content/themes/YOUR-THEME/woocommerce/loop

    Add the below code to the newly created ‘rating.php’ and customize it according to your need.

    <?php
    /**
     * Loop Rating
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/loop/rating.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see         https://docs.woocommerce.com/document/template-structure/
     * @author      WooThemes
     * @package     WooCommerce/Templates
     * @version     3.0.0
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }
    
    global $product;
    
    if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
        return;
    }
    
    $rating_count = $product->get_rating_count();
    $review_count = $product->get_review_count();
    $average      = $product->get_average_rating();
    
    if ( $rating_count >= 0 ) : ?>
    
    	        <?php echo wc_get_rating_html($average, $rating_count); ?>
    		<?php if ( comments_open() ): ?><a href="<?php echo get_permalink() ?>#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s',$review_count,'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>
    	
    
    <?php endif; ?>

    In case this doesn’t work

    Add ‘templates’ folder in ‘woocommerce’ folder and then add ‘loop’ folder in ‘templates’ folder.

    Now the directory would look like this

    /public_html/wp-content/themes/YOUR-THEME/woocommerce/templates/loop

    • This reply was modified 6 years, 7 months ago by Manjunathpmf.
    • This reply was modified 6 years, 7 months ago by Manjunathpmf.
    • This reply was modified 6 years, 7 months ago by Manjunathpmf.
    • This reply was modified 6 years, 7 months ago by Manjunathpmf.

    Hi,

    excellent snippet.

    What is the CSS I have to use to get the count next to the star rating? In my case the count always appears beneath the star rating.

    Thanks a lot and looking forward to hearing from you.

    Best regards,

    THANK YOU FOR THIS!!!!

    Ahhh, I have been trying to figure this out for months but didn’t know how to articulate it well enough to find what I was looking for online!

    Also just to help anyone else out, you should put the woocommerce and loop folder into the theme child folder if you are using a child-theme, otherwise your work will be undone when you update!

    @tabasco86 use display:inline-block; property for both the classes

    Try this

    // Add this snippet to style.css file in your child theme

    .woocommerce ul.products li.product .star-rating,
    .woocommerce ul.products li.product .woocommerce-review-link {
        display:inline-block
    }

    @manjunathpmf,

    awesome! Thanks a lot! I can’t believe I didn’t come up with that earlier! hahaha

    have a great weekend!

    Thread Starter cheonmu

    (@cheonmu)

    @manjunathpmf,

    Thanks for answering!

    is this method do not work on woocommerce`s product widgets?

    I put raiting file in loop/ or templates/loop/ already, but doesnt work.

    Thank you.

    • This reply was modified 5 years, 12 months ago by cheonmu.
    • This reply was modified 5 years, 12 months ago by cheonmu.

    @cheonmu You need to modify the template for that particular widget I guess.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to display review count next to star rating ?’ is closed to new replies.