• Resolved randzgonz02

    (@randzgonz02)


    Hello Team,

    May I know if there’s a way we can include a review percentage of all reviews like what we can see here https://prnt.sc/o247yn? I’m talking about the “4.9” review score/percentage.

    Thanks,
    Randy

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hello there,

    hope you are doing well!

    Please, add the following code in the functions.php file of your active theme:

    if (class_exists('YITH_WooCommerce_Advanced_Reviews')){
        remove_action( 'ywar_summary_prepend', array( YITH_WooCommerce_Advanced_Reviews::get_instance(), 'add_reviews_average_info' ) );
        if (!function_exists('yith_add_reviews_average_info_custom')){
    
            function yith_add_reviews_average_info_custom($product){
                $instance = YITH_WooCommerce_Advanced_Reviews::get_instance();
                if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
                    return;
                }
    
                $product_id = yit_get_prop( $product, 'id' );
                $average    = $instance->get_average_rating( $product_id );
    
                $count      = count( $instance->get_product_reviews_by_rating( $product_id ) );
                $rated_text = sprintf( __( 'Rated %s out of 5 stars', 'yith-woocommerce-advanced-reviews' ), esc_html( $average ) );
    
                if ( $count > 0 ) { ?>
                    <div class="woocommerce-product-rating">
    
                        <div class="star-rating" title="<?php $rated_text; ?>">
                            <span style="width:<?php echo( ( $average / 5 ) * 100 ); ?>%">
    	                        <span class="review-rating-value"><?php echo $rated_text; ?></span>
                            </span>
                        </div>
                        <?php
                        echo $average . ' based on ';
                        ?>
                        <span class="ywar_review_count"><?php printf( "%d %s", $count, _n( " review", " reviews", $count, 'yith-woocommerce-advanced-reviews' ) ); ?></span>
                    </div>
                    <?php
                }
            }
            add_action( 'ywar_summary_prepend', 'yith_add_reviews_average_info_custom' );
        }
    }

    Try it and let us know.

    Have a nice day!

    • This reply was modified 4 years, 10 months ago by YITHEMES.
    Thread Starter randzgonz02

    (@randzgonz02)

    Wow! It works perfectly! Thank you so much! 🙂

    May I know if is this just a custom code or you’re planning to include this on the plugin?

    Cheers!
    Randy

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Review Percentage’ is closed to new replies.