• How can I add total review amount text next to star rating on product page.

    Right now it just shows the star and does not show how many reviews there are.

    Can I add it with CSS code ?

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • This can’t be done with CSS but instead needs PHP coding.
    You really need to be experienced with PHP and find the action hook that inserts into the right spot and enter this code:

    function action_callback( $arg ) {
    
        $product = wc_get_product( get_queried_object_id() );
        // Return the review count.
        return $product->get_review_count();
    }
    add_action( 'woocommerce_action', 'action_callback', 10, 2 );

    NOTE: woocommerce_action needs to replaced with the appropriate action hook – you can find the right one here: https://woocommerce.github.io/code-reference/hooks/hooks.html

    Thread Starter homaaa

    (@homaaa)

    i added this code to funtion.php but nothing happened

    Thread Starter homaaa

    (@homaaa)

    can you please tell me easier way i can do it?

    There is no other way to do it – You need to know how to code in PHP because the PHP files need to be edited to make it work.

    The example uses action hooks so you will need to have an understanding on how hooks work:
    https://wpklik.com/wordpress-tutorials/woocommerce-hooks/#how-to-change-positions-of-price-and-ratings

    The hook is the bit that inserts the code into the right spot – the code to generate the rating is in the original answer.

    Figuring it out is not simple. You would need to identify exactly where in the code the function needs to go, identify the correct action hook (looks like it might be this one: add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 10 );) and then add the code to add the review

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can i add total review amount next to star rating on product page’ is closed to new replies.