Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #854165

    JakWalker
    Participant

    Hi Guys

    Absolutely Love X Theme!

    Just one issue I can’t seem to work out and that is how to add woocommerce stars under the product title on a single page.

    If I activate another theme they are showing but not on X Theme, I have looked at previous forum posts but none seem to help.

    #854172

    Thai
    Moderator

    Hi There,

    Please add the following code under functions.php file under child theme:

    add_action( 'woocommerce_single_product_summary', 'x_print_rating', 6 );
    function x_print_rating(){
    	global $woocommerce, $product;
    	$average = $product->get_average_rating();
    
    	echo '<div class="star-rating x-star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', '__x__' ).'</span></div>';
    }

    Hope it helps 🙂

    #854227

    JakWalker
    Participant

    Fantastic that worked perfectly!

    How would I add the the link next to the stars saying how many customers reviewed?

    #854260

    Thai
    Moderator

    Hi There,

    Please update the previous code a bit:

    add_action( 'woocommerce_single_product_summary', 'x_print_rating', 6 );
    function x_print_rating(){
    	global $woocommerce, $product;
    	$average = $product->get_average_rating();
    	$count   = $product->get_review_count() ? $product->get_review_count() : 0;
    
    	echo '<div style="display: inline-block;" class="star-rating x-star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>';
    	echo '<div style="display: inline-block;" class="x-review-count">'. $count . __(' Reviews', '__x__') .'</div>';
    }

    Hope it helps 🙂

    #854306

    JakWalker
    Participant

    Few Tweaks but again perfect… exactly what I needed!

    Thank you very much for that!

    #854316

    Thai
    Moderator

    You’re very welcome 🙂

    If you need anything else, please let us know.