Add stars rating and average to product “Review” item menu in Woocommerce





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I'm trying to add the following: "4.5 / 5 (5 reviews)" but without the "" to the review tab for all WooCommerce products.



I've accomplished to add the stars and some text, but I cannot figure out how to make the text into "4.5 / 5 (5 reviews)". Here's the code I'm using. Just to be clear, I want to keep the stars.



add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
function add_stars_to_review_tab( $title ) {
global $product;

$average_rating = $product->get_average_rating();
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();

if( ! empty($average_rating) && $average_rating > 0 )
$title = '<div>' . $title . '</div>
<div class="stars">' . wc_get_rating_html($average_rating) . ' based on ' . $rating_count. ' reviews' . '</div>';

return $title;
}









share|improve this question































    2















    I'm trying to add the following: "4.5 / 5 (5 reviews)" but without the "" to the review tab for all WooCommerce products.



    I've accomplished to add the stars and some text, but I cannot figure out how to make the text into "4.5 / 5 (5 reviews)". Here's the code I'm using. Just to be clear, I want to keep the stars.



    add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
    function add_stars_to_review_tab( $title ) {
    global $product;

    $average_rating = $product->get_average_rating();
    $rating_count = $product->get_rating_count();
    $review_count = $product->get_review_count();

    if( ! empty($average_rating) && $average_rating > 0 )
    $title = '<div>' . $title . '</div>
    <div class="stars">' . wc_get_rating_html($average_rating) . ' based on ' . $rating_count. ' reviews' . '</div>';

    return $title;
    }









    share|improve this question



























      2












      2








      2








      I'm trying to add the following: "4.5 / 5 (5 reviews)" but without the "" to the review tab for all WooCommerce products.



      I've accomplished to add the stars and some text, but I cannot figure out how to make the text into "4.5 / 5 (5 reviews)". Here's the code I'm using. Just to be clear, I want to keep the stars.



      add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
      function add_stars_to_review_tab( $title ) {
      global $product;

      $average_rating = $product->get_average_rating();
      $rating_count = $product->get_rating_count();
      $review_count = $product->get_review_count();

      if( ! empty($average_rating) && $average_rating > 0 )
      $title = '<div>' . $title . '</div>
      <div class="stars">' . wc_get_rating_html($average_rating) . ' based on ' . $rating_count. ' reviews' . '</div>';

      return $title;
      }









      share|improve this question
















      I'm trying to add the following: "4.5 / 5 (5 reviews)" but without the "" to the review tab for all WooCommerce products.



      I've accomplished to add the stars and some text, but I cannot figure out how to make the text into "4.5 / 5 (5 reviews)". Here's the code I'm using. Just to be clear, I want to keep the stars.



      add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
      function add_stars_to_review_tab( $title ) {
      global $product;

      $average_rating = $product->get_average_rating();
      $rating_count = $product->get_rating_count();
      $review_count = $product->get_review_count();

      if( ! empty($average_rating) && $average_rating > 0 )
      $title = '<div>' . $title . '</div>
      <div class="stars">' . wc_get_rating_html($average_rating) . ' based on ' . $rating_count. ' reviews' . '</div>';

      return $title;
      }






      php wordpress woocommerce product rating






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '18 at 6:08









      James Z

      11.2k71936




      11.2k71936










      asked Nov 16 '18 at 19:25







      user10551357































          2 Answers
          2






          active

          oldest

          votes


















          1














          Update 2: The following code will display something like "4.5/5 (5 reviews)" below the review item menu title and stars in Woocommerce single product pages tabs:



          add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
          function add_stars_to_review_tab( $title ) {
          global $product;

          $average_rating = $product->get_average_rating();
          $rating_count = $product->get_rating_count();
          $review_count = $product->get_review_count();

          if( ! empty($average_rating) && $average_rating > 0 ) {
          return '<div>' . $title . '</div>' . wc_get_rating_html($average_rating) . sprintf(
          '<div class="stars">%s / 5 (%s %s)</div>',
          $average_rating,
          $review_count,
          _n( "review", "reviews", $review_count, "woocommerce" )
          );
          }
          return $title;
          }


          Code goes in function.php file of your active child theme (active theme). Tested and works.



          enter image description here






          share|improve this answer


























          • thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

            – user10551357
            Nov 16 '18 at 20:07











          • @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

            – LoicTheAztec
            Nov 16 '18 at 20:10













          • my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

            – user10551357
            Nov 16 '18 at 20:12











          • thank you. very kind of you to help (once again).

            – user10551357
            Nov 16 '18 at 20:22











          • Yes, the title stays ;) I've changed that anyway using a different function.

            – user10551357
            Nov 16 '18 at 20:24





















          0














          You can add star rating and average to product "Review" item in WooCommerce with just few clicks.



          Rating Score



          I recently found TrustFeed reviews for WooCommerce, it is a new plugin that helped me to replace the basic and boring WooCommerce reviews forms with an advanced and dynamic rating and reviews solution that actually inspire shoppers to buy more!



          It comes with special features to help honest online businesses to collect and showcase customer reviews to boost sales, conversions, trust and social proof.



          Some special features are:




          • Create custom satisfaction surveys


            • Star Ratings

            • Dynamic Tags

            • Text Reviews

            • More coming…



          • Send Mail After Purchase emails to encourage shoppers to leave reviews.

          • Collect reviews at scale.

          • Showcase reviews on key conversion points of your website.

          • Display your reviews in an useful, responsive and customizable format.

          • Moderate and manage feedback/reviews.

          • Create a mini-site to increase your SEO with User Generated Content

          • Customize widget’s look and feel.

          • Learn from data driven insights


          The plugin is free and can be dowloaded via official WordPress plugin repository:



          https://wordpress.org/plugins/trustfeed-reviews-and-customer-feedback-for-woocommerce/




          • To learn more about TrustFeed you can visit www.trustfeed.co

          • To view the admin panel, just login at https://admin.trustfeed.co and create a free account.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344184%2fadd-stars-rating-and-average-to-product-review-item-menu-in-woocommerce%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown
























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Update 2: The following code will display something like "4.5/5 (5 reviews)" below the review item menu title and stars in Woocommerce single product pages tabs:



            add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
            function add_stars_to_review_tab( $title ) {
            global $product;

            $average_rating = $product->get_average_rating();
            $rating_count = $product->get_rating_count();
            $review_count = $product->get_review_count();

            if( ! empty($average_rating) && $average_rating > 0 ) {
            return '<div>' . $title . '</div>' . wc_get_rating_html($average_rating) . sprintf(
            '<div class="stars">%s / 5 (%s %s)</div>',
            $average_rating,
            $review_count,
            _n( "review", "reviews", $review_count, "woocommerce" )
            );
            }
            return $title;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.



            enter image description here






            share|improve this answer


























            • thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

              – user10551357
              Nov 16 '18 at 20:07











            • @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

              – LoicTheAztec
              Nov 16 '18 at 20:10













            • my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

              – user10551357
              Nov 16 '18 at 20:12











            • thank you. very kind of you to help (once again).

              – user10551357
              Nov 16 '18 at 20:22











            • Yes, the title stays ;) I've changed that anyway using a different function.

              – user10551357
              Nov 16 '18 at 20:24


















            1














            Update 2: The following code will display something like "4.5/5 (5 reviews)" below the review item menu title and stars in Woocommerce single product pages tabs:



            add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
            function add_stars_to_review_tab( $title ) {
            global $product;

            $average_rating = $product->get_average_rating();
            $rating_count = $product->get_rating_count();
            $review_count = $product->get_review_count();

            if( ! empty($average_rating) && $average_rating > 0 ) {
            return '<div>' . $title . '</div>' . wc_get_rating_html($average_rating) . sprintf(
            '<div class="stars">%s / 5 (%s %s)</div>',
            $average_rating,
            $review_count,
            _n( "review", "reviews", $review_count, "woocommerce" )
            );
            }
            return $title;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.



            enter image description here






            share|improve this answer


























            • thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

              – user10551357
              Nov 16 '18 at 20:07











            • @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

              – LoicTheAztec
              Nov 16 '18 at 20:10













            • my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

              – user10551357
              Nov 16 '18 at 20:12











            • thank you. very kind of you to help (once again).

              – user10551357
              Nov 16 '18 at 20:22











            • Yes, the title stays ;) I've changed that anyway using a different function.

              – user10551357
              Nov 16 '18 at 20:24
















            1












            1








            1







            Update 2: The following code will display something like "4.5/5 (5 reviews)" below the review item menu title and stars in Woocommerce single product pages tabs:



            add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
            function add_stars_to_review_tab( $title ) {
            global $product;

            $average_rating = $product->get_average_rating();
            $rating_count = $product->get_rating_count();
            $review_count = $product->get_review_count();

            if( ! empty($average_rating) && $average_rating > 0 ) {
            return '<div>' . $title . '</div>' . wc_get_rating_html($average_rating) . sprintf(
            '<div class="stars">%s / 5 (%s %s)</div>',
            $average_rating,
            $review_count,
            _n( "review", "reviews", $review_count, "woocommerce" )
            );
            }
            return $title;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.



            enter image description here






            share|improve this answer















            Update 2: The following code will display something like "4.5/5 (5 reviews)" below the review item menu title and stars in Woocommerce single product pages tabs:



            add_filter( 'woocommerce_product_reviews_tab_title', 'add_stars_to_review_tab', 98 );
            function add_stars_to_review_tab( $title ) {
            global $product;

            $average_rating = $product->get_average_rating();
            $rating_count = $product->get_rating_count();
            $review_count = $product->get_review_count();

            if( ! empty($average_rating) && $average_rating > 0 ) {
            return '<div>' . $title . '</div>' . wc_get_rating_html($average_rating) . sprintf(
            '<div class="stars">%s / 5 (%s %s)</div>',
            $average_rating,
            $review_count,
            _n( "review", "reviews", $review_count, "woocommerce" )
            );
            }
            return $title;
            }


            Code goes in function.php file of your active child theme (active theme). Tested and works.



            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 16 '18 at 20:22

























            answered Nov 16 '18 at 19:56









            LoicTheAztecLoicTheAztec

            98k1472114




            98k1472114













            • thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

              – user10551357
              Nov 16 '18 at 20:07











            • @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

              – LoicTheAztec
              Nov 16 '18 at 20:10













            • my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

              – user10551357
              Nov 16 '18 at 20:12











            • thank you. very kind of you to help (once again).

              – user10551357
              Nov 16 '18 at 20:22











            • Yes, the title stays ;) I've changed that anyway using a different function.

              – user10551357
              Nov 16 '18 at 20:24





















            • thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

              – user10551357
              Nov 16 '18 at 20:07











            • @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

              – LoicTheAztec
              Nov 16 '18 at 20:10













            • my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

              – user10551357
              Nov 16 '18 at 20:12











            • thank you. very kind of you to help (once again).

              – user10551357
              Nov 16 '18 at 20:22











            • Yes, the title stays ;) I've changed that anyway using a different function.

              – user10551357
              Nov 16 '18 at 20:24



















            thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

            – user10551357
            Nov 16 '18 at 20:07





            thank you very much! Only problem is that now the stars are gone. If you could please add them back I would appreciate it.

            – user10551357
            Nov 16 '18 at 20:07













            @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

            – LoicTheAztec
            Nov 16 '18 at 20:10







            @WooDevil Can you please clarify your question, as we don't know what you want exactly… do I keep reviews, the stars and the rest in 3 lines? because you will have redundent things as the number of reviews after the title (by default)

            – LoicTheAztec
            Nov 16 '18 at 20:10















            my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

            – user10551357
            Nov 16 '18 at 20:12





            my apologies if it was unclear. Yes, please keep the stars (wc_get_rating_html) and underneath them, add the "4.5 / 5 (5 reviews)"part.

            – user10551357
            Nov 16 '18 at 20:12













            thank you. very kind of you to help (once again).

            – user10551357
            Nov 16 '18 at 20:22





            thank you. very kind of you to help (once again).

            – user10551357
            Nov 16 '18 at 20:22













            Yes, the title stays ;) I've changed that anyway using a different function.

            – user10551357
            Nov 16 '18 at 20:24







            Yes, the title stays ;) I've changed that anyway using a different function.

            – user10551357
            Nov 16 '18 at 20:24















            0














            You can add star rating and average to product "Review" item in WooCommerce with just few clicks.



            Rating Score



            I recently found TrustFeed reviews for WooCommerce, it is a new plugin that helped me to replace the basic and boring WooCommerce reviews forms with an advanced and dynamic rating and reviews solution that actually inspire shoppers to buy more!



            It comes with special features to help honest online businesses to collect and showcase customer reviews to boost sales, conversions, trust and social proof.



            Some special features are:




            • Create custom satisfaction surveys


              • Star Ratings

              • Dynamic Tags

              • Text Reviews

              • More coming…



            • Send Mail After Purchase emails to encourage shoppers to leave reviews.

            • Collect reviews at scale.

            • Showcase reviews on key conversion points of your website.

            • Display your reviews in an useful, responsive and customizable format.

            • Moderate and manage feedback/reviews.

            • Create a mini-site to increase your SEO with User Generated Content

            • Customize widget’s look and feel.

            • Learn from data driven insights


            The plugin is free and can be dowloaded via official WordPress plugin repository:



            https://wordpress.org/plugins/trustfeed-reviews-and-customer-feedback-for-woocommerce/




            • To learn more about TrustFeed you can visit www.trustfeed.co

            • To view the admin panel, just login at https://admin.trustfeed.co and create a free account.






            share|improve this answer




























              0














              You can add star rating and average to product "Review" item in WooCommerce with just few clicks.



              Rating Score



              I recently found TrustFeed reviews for WooCommerce, it is a new plugin that helped me to replace the basic and boring WooCommerce reviews forms with an advanced and dynamic rating and reviews solution that actually inspire shoppers to buy more!



              It comes with special features to help honest online businesses to collect and showcase customer reviews to boost sales, conversions, trust and social proof.



              Some special features are:




              • Create custom satisfaction surveys


                • Star Ratings

                • Dynamic Tags

                • Text Reviews

                • More coming…



              • Send Mail After Purchase emails to encourage shoppers to leave reviews.

              • Collect reviews at scale.

              • Showcase reviews on key conversion points of your website.

              • Display your reviews in an useful, responsive and customizable format.

              • Moderate and manage feedback/reviews.

              • Create a mini-site to increase your SEO with User Generated Content

              • Customize widget’s look and feel.

              • Learn from data driven insights


              The plugin is free and can be dowloaded via official WordPress plugin repository:



              https://wordpress.org/plugins/trustfeed-reviews-and-customer-feedback-for-woocommerce/




              • To learn more about TrustFeed you can visit www.trustfeed.co

              • To view the admin panel, just login at https://admin.trustfeed.co and create a free account.






              share|improve this answer


























                0












                0








                0







                You can add star rating and average to product "Review" item in WooCommerce with just few clicks.



                Rating Score



                I recently found TrustFeed reviews for WooCommerce, it is a new plugin that helped me to replace the basic and boring WooCommerce reviews forms with an advanced and dynamic rating and reviews solution that actually inspire shoppers to buy more!



                It comes with special features to help honest online businesses to collect and showcase customer reviews to boost sales, conversions, trust and social proof.



                Some special features are:




                • Create custom satisfaction surveys


                  • Star Ratings

                  • Dynamic Tags

                  • Text Reviews

                  • More coming…



                • Send Mail After Purchase emails to encourage shoppers to leave reviews.

                • Collect reviews at scale.

                • Showcase reviews on key conversion points of your website.

                • Display your reviews in an useful, responsive and customizable format.

                • Moderate and manage feedback/reviews.

                • Create a mini-site to increase your SEO with User Generated Content

                • Customize widget’s look and feel.

                • Learn from data driven insights


                The plugin is free and can be dowloaded via official WordPress plugin repository:



                https://wordpress.org/plugins/trustfeed-reviews-and-customer-feedback-for-woocommerce/




                • To learn more about TrustFeed you can visit www.trustfeed.co

                • To view the admin panel, just login at https://admin.trustfeed.co and create a free account.






                share|improve this answer













                You can add star rating and average to product "Review" item in WooCommerce with just few clicks.



                Rating Score



                I recently found TrustFeed reviews for WooCommerce, it is a new plugin that helped me to replace the basic and boring WooCommerce reviews forms with an advanced and dynamic rating and reviews solution that actually inspire shoppers to buy more!



                It comes with special features to help honest online businesses to collect and showcase customer reviews to boost sales, conversions, trust and social proof.



                Some special features are:




                • Create custom satisfaction surveys


                  • Star Ratings

                  • Dynamic Tags

                  • Text Reviews

                  • More coming…



                • Send Mail After Purchase emails to encourage shoppers to leave reviews.

                • Collect reviews at scale.

                • Showcase reviews on key conversion points of your website.

                • Display your reviews in an useful, responsive and customizable format.

                • Moderate and manage feedback/reviews.

                • Create a mini-site to increase your SEO with User Generated Content

                • Customize widget’s look and feel.

                • Learn from data driven insights


                The plugin is free and can be dowloaded via official WordPress plugin repository:



                https://wordpress.org/plugins/trustfeed-reviews-and-customer-feedback-for-woocommerce/




                • To learn more about TrustFeed you can visit www.trustfeed.co

                • To view the admin panel, just login at https://admin.trustfeed.co and create a free account.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 9 at 0:35









                AlexAlex

                1




                1






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344184%2fadd-stars-rating-and-average-to-product-review-item-menu-in-woocommerce%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Lugert, Oklahoma