• Resolved bostrb

    (@boosterbast)


    Hi,

    I have started using the plugin. So far so good. I do have a question. On the shop pages in woocommerce. The plugin correctly shows the star rating. How can I add that it also shows the number of reviews?

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor Paul

    (@pryley)

    You can do this with some CSS.

    To display the review count before the stars:

    .glsrw-loop-rating [data-reviews]::before {
    content: attr(data-reviews);
    margin-inline-end: .25em;
    }

    To display the review count after the stars:

    .glsrw-loop-rating [data-reviews]::after {
    content: attr(data-reviews);
    margin-inline-start: .25em;
    }
    Thread Starter bostrb

    (@boosterbast)

    Hi Paul,

    Thanks for the quick reply. I have added the CSS, but the review count is not showing. Only the stars. When I inspect the stars is does not show loop rating. it shows:

    <div class=”glsr glsr-default glsr-ltr”><div class=”glsr-star-rating glsr-stars” role=”img” aria-label=”Waardering 5 van 5 sterren” data-rating=”5″ data-reviews=”0″><span class=”glsr-star glsr-star-full” aria-hidden=”true”></span><span class=”glsr-star glsr-star-full” aria-hidden=”true”></span><span class=”glsr-star glsr-star-full” aria-hidden=”true”></span><span class=”glsr-star glsr-star-full” aria-hidden=”true”></span><span class=”glsr-star glsr-star-full” aria-hidden=”true”></span></div></div>

    • This reply was modified 1 year, 2 months ago by bostrb.
    Plugin Contributor Paul

    (@pryley)

    Have you enabled the WooCommerce integration in Site Reviews? This will automatically add the rating to the products on the shop page.

    If you are not, then you will need to change the CSS to something like this (adjust the CSS selectors as needed):

    .products .glsr-star-rating[data-reviews]::after {
    content: attr(data-reviews);
    margin-inline-start: .25em;
    }
    Thread Starter bostrb

    (@boosterbast)

    Hi Paul,

    Yes I have enabled the woocommerce integration. It indeed automatically adds the rating. but only the stars (not the amount of reviews)

    Plugin Contributor Paul

    (@pryley)

    What is the URL?

    Thread Starter bostrb

    (@boosterbast)

    Hi Paul,

    I have added the website link to my profile.

    Plugin Contributor Paul

    (@pryley)

    The CSS I gave you here works.

    However, there is no point in using it because the review count for products on the shop page will always be zero because you are using the WoodMart theme.

    The WoodMart theme has its own rating functions that are used in the theme. The functions use the woocommerce_get_star_rating_html filter hook used by WooCommerce which allow three parameters: $html, $rating, $count. The $count parameter should be the review count, but WoodMart always passes 0 as the review count for the rating.

    • This reply was modified 1 year, 2 months ago by Paul.
    Thread Starter bostrb

    (@boosterbast)

    Ah I see,

    Is there a way to remove those stars from the loop? and add the review_summary shortcode there with the following method: https://wordpress.org/support/topic/shortcode-for-review-count/

    • This reply was modified 1 year, 2 months ago by bostrb.
    Thread Starter bostrb

    (@boosterbast)

    If it possible to remove the star rating that is in the loop. I could output the shortcode for the rating summary with: add_action(‘woocommerce_after_shop_loop_item_title’, ‘add_custom_shortcode_for_variable_products’, 6);

    Plugin Contributor Paul

    (@pryley)

    Ignore the CSS above and just use this PHP code snippet: https://pastebin.com/z95RH0iv

    Make sure that you enable the “Show reviews count” option in “WoodMart > Theme Settings > Product archive > Product styles > Elements”.

    This fix will be included in Site Reviews v8.0

    Thread Starter bostrb

    (@boosterbast)

    Awesome. Will test it tomorrow morning and report the result

    Thread Starter bostrb

    (@boosterbast)

    Hi Paul,

    I just tested it. The code seems to work. However it does seem to cause an error:

    Backend fatal error: PHP Fatal error:  Uncaught Error: Call to a member function get_review_count() on null in /XXXX/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/template-tags.php:2805\nStack trace:\n#0 /XXXX/public_html/wp-content/themes/woodmart-child/functions.php(391): woodmart_show_reviews_count()\n#1 /XXXX/public_html/wp-includes/class-wp-hook.php(326): glsr_woodmart_product_rating_count()\n#2 /XXXX/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters()\n#3 /XXXX/public_html/wp-content/plugins/woocommerce/includes/wc-template-functions.php(3893): apply_filters()\n#4 /XXXX/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php(586): wc_get_rating_html()\n#5 /XXXX/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php(498): Automattic\\WooCommerce\\Blocks\\BlockTypes\\AbstractProductGrid->get_rating_html()\n#6 [internal function]: Automattic\\WooCommerce\\Blocks\\BlockTypes\\AbstractProductGrid->render_product()\n#7 /XXXX/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockTypes/AbstractProductGrid.php(132): array_map()\n#8 /XXXX/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php(98): Automattic\\WooCommerce\\Blocks\\BlockTypes\\AbstractProductGrid->render()\n#9 /XXXX/public_html/wp-includes/class-wp-block.php(586): Automattic\\WooCommerce\\Blocks\\BlockTypes\\AbstractBlock->render_callback()\n#10 /XXXX/public_html/wp-includes/blocks.php(2359): WP_Block->render()\n#11 /XXXX/public_html/wp-includes/blocks.php(2431): render_block()\n#12 /XXXX/public_html/wp-includes/class-wp-hook.php(324): do_blocks()\n#13 /XXXX/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters()\n#14 /XXXX/public_html/wp-includes/post-template.php(256): apply_filters()\n#15 /XXXX/public_html/wp-content/themes/woodmart/inc/template-tags/template-tags.php(620): the_content()\n#16 /XXXX/public_html/wp-content/themes/woodmart/inc/template-tags/template-tags.php(561): woodmart_get_full_content()\n#17 /XXXX/public_html/wp-content/themes/woodmart/content.php(119): woodmart_get_content()\n#18 /XXXX/public_html/wp-includes/template.php(812): require(‘/XXXX…’)\n#19 /XXXX/public_html/wp-includes/template.php(745): load_template()\n#20 /XXXX/public_html/wp-includes/general-template.php(206): locate_template()\n#21 /XXXX/public_html/wp-content/themes/woodmart/single.php(37): get_template_part()\n#22 /XXXX/public_html/wp-includes/template-loader.php(106): include(‘/XXXX…’)\n#23 /XXXX/public_html/wp-blog-header.php(19): require_once(‘/XXXX…’)\n#24 /XXXX/public_html/index.php(17): require(‘/XXXX…’)\n#25 {main}\n  thrown in /XXXX/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/template-tags.php on line 2805\n

    • This reply was modified 1 year, 2 months ago by bostrb.
    • This reply was modified 1 year, 2 months ago by bostrb.
    • This reply was modified 1 year, 2 months ago by bostrb.
    Thread Starter bostrb

    (@boosterbast)

    I have added this to the code snippet. Not sure if you agree with it:

    global $product;

    if ( ! is_a( $product, ‘WC_Product’ ) ) {

    return $html; // or wrap here if you prefer

    }

    • This reply was modified 1 year, 2 months ago by bostrb.
    • This reply was modified 1 year, 2 months ago by bostrb.
    Plugin Contributor Paul

    (@pryley)

    I have added this to the code snippet. Not sure if you agree with it:

    Looks good!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘How to add review count to star rating for woocommere product archive pages’ is closed to new replies.