• Resolved richardkacer

    (@richardkacer)


    Hello guys,

    I saw code from @kimvt1991 in the topic on the forum here:https://www.ads-software.com/support/topic/add-count-of-the-number-of-reviews-alongside-star-rating/

    And one of the codes worked for me so thank you very much for that. It shows count of reviews alongside star rating in the archive page but I am now approaching you with the question if I can add it to a home page to a woo-slider ?

    The code:

    }

    add_filter( ‘woocommerce_product_get_rating_html’, function ( $html, $rating, $count ) {
    global $product;
    if ( $html && is_archive() && $product) {
    $html .= sprintf( ‘<span>(%s)</span>’, $product->get_rating_count() );
    }

    return $html;
    }, 10, 3 );

    Thank you in advance

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,
    Please try:

    add_filter( 'woocommerce_product_get_rating_html', function ( $html, $rating, $count ) {
    	global $product;
    	if ( $html && !is_admin() && $product) {
    		$html .= sprintf( '<span>(%s)</span>', $product->get_rating_count() );
    	}
    
    	return $html;
    }, 10, 3 );

    Best regards

    Thread Starter richardkacer

    (@richardkacer)

    Works perfectly ! Thank you very much ! Maybe I would also like to hide the old one which was on the single product page .. now on the whole page it is perfect but on the single product page there are like two brackets with the number , the one you added via code and the old one so I want to hide the old one if possible. Thank you

    Please use below one instead:

    add_filter( 'woocommerce_product_get_rating_html', function ( $html, $rating, $count ) {
    	global $product;
    	if ( $html && !is_admin() && $product && !is_product()) {
    		$html .= sprintf( '<span>(%s)</span>', $product->get_rating_count() );
    	}
    
    	return $html;
    }, 10, 3 );
    Thread Starter richardkacer

    (@richardkacer)

    Okay, it shows me this error in the first line :

    syntax error, unexpected token “&”

    Please copy the code directly from my reply above.

    Thread Starter richardkacer

    (@richardkacer)

    Is still ok but on the single product page there are still yours and our original count. Maybe we can hide it by like CSS or something. If not is ok, I am thankful anyways.

    Yes, you can hide either of them with css. Please enable the working snippet then I will help you with custom css.

    Thread Starter richardkacer

    (@richardkacer)

    Yup now it works, no CSS needed. Did you change something ? ,, thank you very much MAN,, Maybe I would need some more code for stock status everywhere on the page under or above the stars if you could do that I would very much appreciate it, your job is high quality !!

    You can adjust the code as below but I think it will not display well:

    add_filter( 'woocommerce_product_get_rating_html', function ( $html, $rating, $count ) {
    	global $product;
    	if ( $html && !is_admin() && $product && !is_product()) {
    		$html .= sprintf( '<span>(%s)</span>', $product->get_rating_count() );
    		$html .='<div style="width: 100%">'.$product->get_stock_status().'</div>';
    	}
    
    	return $html;
    }, 10, 3 );

    You may also want to add below css(to customize/additional css) to make stock status display on a new line:

    li.rating{
        flex-wrap: wrap;
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Number of reviews alongside Star Rating’ is closed to new replies.