Files
wc-bootstrap/templates/loop/rating.html.twig

41 lines
1.4 KiB
Twig
Raw Normal View History

{#
# Loop Product Rating (Bootstrap 5 Override)
#
# Renders star ratings for products in the shop loop.
#
# Expected context:
# product - WC_Product object with:
# .get_average_rating() - Average rating (0-5)
# .get_review_count() - Number of reviews
# reviews_enabled - Whether reviews/ratings are enabled (boolean)
#
# WooCommerce PHP equivalent: loop/rating.php
#
# @package WcBootstrap
# @since 0.1.0
#}
{% if reviews_enabled is not defined or reviews_enabled %}
{% if product is defined and product.get_average_rating() > 0 %}
{% set rating = product.get_average_rating() %}
{% set count = product.get_review_count() %}
<div class="wc-star-rating d-flex align-items-center gap-1 mb-1"
role="img"
aria-label="{{ __('%s out of 5 stars')|format(rating) }}">
{% for i in 1..5 %}
{% if i <= rating|round(0, 'floor') %}
<i class="bi bi-star-fill text-warning" aria-hidden="true"></i>
{% elseif i - rating < 1 %}
<i class="bi bi-star-half text-warning" aria-hidden="true"></i>
{% else %}
<i class="bi bi-star text-warning" aria-hidden="true"></i>
{% endif %}
{% endfor %}
{% if count > 0 %}
<small class="text-body-secondary">({{ count }})</small>
{% endif %}
</div>
{% endif %}
{% endif %}