Useful Snippets

Show Product Percentage instead of Comment Count on WooCommerce

Pinterest LinkedIn Tumblr

Hi WooLovers.

Today, We’re going to manipulate comment counts. Numbers are good but visualizing something is much more sense for the customer. The web is full of text and people only scan this text but when we see images or visual things we give pay attention. So you can visualize this code by CSS and get your customer’s attention.

Add the following code on your functions.php

 *  Remove default rating code from woocommerce\templates\single-product\rating.php 
 *  Can do same thing by editing that template file
 *  Add the following code on your functions.php
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10);

add_action( 'woocommerce_after_shop_loop_item_title', 'amc_function_add_rating_percentage', 5  );
add_action( 'woocommerce_single_product_summary', 'amc_function_add_rating_percentage', 5  );
function  amc_function_add_rating_percentage() { 
    global $product;  
    $rating_count = $product->get_rating_count(); 
    $average      = $product->get_average_rating(); 
    $average_percent = $average * 100/5;
    if($rating_count >0){
        echo '<div class="woocommerce-product-rating">'.wc_get_rating_html( $average, $rating_count ).esc_html__( '('.$average_percent.'% customers satisfied )' , 'amc' ).'</div>'; 

Another tip is showing discount percentage as a label on product images. This can increase your sellings. Click here to learn how to it.

Write A Comment