Site logo

[Resolved] Displaying number of reviews on product archive pages in Woocommerce

Home Forums Support [Resolved] Displaying number of reviews on product archive pages in Woocommerce

Home Forums Support Displaying number of reviews on product archive pages in Woocommerce

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #2515455
    David
    Staff
    Customer Support

    And this is where Woo gets real tricky 🙂

    1. The PHP Snippet would look like this:

    add_filter('woocommerce_product_get_rating_html', function( $html, $rating, $count ){
        global $woocommerce_loop;
        global $product;
        $loop_data = $woocommerce_loop['name'];
        $review_count = $product->get_review_count();
        if ( $review_count && $loop_data ) {
            $html = '<div class="rating-wrapper">' . $html . $review_count . '</div>';
        } elseif ( $review_count < 1 && !is_product() ) {
            $html = '';
        }
        return $html;
    },10,3);

    This checks that the reviews are in the loop, so it doesn’t mess with the one below the single product title.
    NOTE: I don’t think it will remove empty stars on the related / upsell products…

    2. And this is the CSS where we make it only remove margins if the rating-wrapper is present.

    ul.products li.product.woocommerce-text-align-center .rating-wrapper .star-rating {
        margin: 0 !important;
    }
    .rating-wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 10px;
    }
    #2515484
    Dominic

    Thank you once again!
    It worked.

    I used this CSS for the empty star rating:

    .woocommerce .star-rating:before {
    	opacity: 0;
    } 

    It works and I think this is the correct CSS that targets only the empty star rating on the single product page. (and no other objects)

    #2515788
    David
    Staff
    Customer Support

    You’re welcome

    #2568968
    Jordan

    I used the code provided (in the code snippets plugin) and it worked fine on product category pages but it gave PHP errors on the homepage.

    #2568995
    Ying
    Staff
    Customer Support

    Hi Jordan,

    Is your homepage the shop page or a static page?

    The code will NOT work on a static page.

    Can you open a new topic and attach your site link?

    #2569115
    Jordan

    Thank you for the fast reply, Ying. Here is the new thread: https://generatepress.com/forums/topic/php-code-for-review-count-on-product-archive-pages/

Viewing 6 posts - 16 through 21 (of 21 total)
  • The topic ‘Displaying number of reviews on product archive pages in Woocommerce’ is closed to new replies.