default.php
59 lines
| 1 | <?php defined('ABSPATH') || exit; |
| 2 | |
| 3 | global $product; |
| 4 | if(!$product){ |
| 5 | return; |
| 6 | } |
| 7 | |
| 8 | // return if review not available |
| 9 | $is_editor = ($post_type == \ShopEngine\Core\Template_Cpt::TYPE) ? true : false; |
| 10 | $rating_count = $product->get_rating_count(); |
| 11 | $show_zero_reviews = isset($settings['shopengine_show_zero_reviews']) && $settings['shopengine_show_zero_reviews'] === 'yes'; |
| 12 | |
| 13 | if(!$is_editor && (!post_type_supports('product', 'comments') || !wc_review_ratings_enabled() || (!$show_zero_reviews && $rating_count <= 0) || !function_exists('woocommerce_template_single_rating'))) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | \ShopEngine\Widgets\Widget_Helper::instance()->wc_template_filter_by_match('woocommerce/single-product/rating.php', 'templates/single-product/rating.php'); |
| 18 | |
| 19 | $shopengine_rating_singular_label = !empty($settings['shopengine_rating_singular_label']) ? $settings['shopengine_rating_singular_label'] : __('Customer Review', 'shopengine'); |
| 20 | $shopengine_rating_plural_label = !empty($settings['shopengine_rating_plural_label']) ? $settings['shopengine_rating_plural_label'] : __('Customer Reviews', 'shopengine'); |
| 21 | |
| 22 | $rating_count = $product->get_rating_count(); |
| 23 | $review_count = $product->get_review_count(); |
| 24 | $average = $product->get_average_rating(); |
| 25 | ?> |
| 26 | |
| 27 | <div class="shopengine-product-rating"> |
| 28 | |
| 29 | <?php if($is_editor) : ?> |
| 30 | |
| 31 | <div class="woocommerce-product-rating"> |
| 32 | <?php shopengine_content_render( wc_get_rating_html( $average, $rating_count ) ); ?> |
| 33 | <a title="<?php esc_html_e('Product Reviews','shopengine')?>" href="#reviews" class="woocommerce-review-link" rel="nofollow"> |
| 34 | (<?php shopengine_content_render(sprintf( _n( '%s '. $shopengine_rating_singular_label, '%s ' . $shopengine_rating_plural_label, $rating_count, 'shopengine' ), '<span class="count">' . esc_html( $review_count ) . '</span>' )); ?>) |
| 35 | </a> |
| 36 | </div> |
| 37 | |
| 38 | <?php else : |
| 39 | |
| 40 | |
| 41 | if ( ! wc_review_ratings_enabled() ) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | if ( $rating_count > 0 || ($show_zero_reviews && $rating_count <= 0) ) : ?> |
| 46 | |
| 47 | <div class="woocommerce-product-rating"> |
| 48 | <?php shopengine_content_render( wc_get_rating_html( $average, $rating_count ) ); ?> |
| 49 | <?php if ( comments_open() ) : ?> |
| 50 | <?php //phpcs:disable ?> |
| 51 | <a title="<?php esc_html_e('Product Reviews','shopengine')?>" href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s ' . $shopengine_rating_singular_label, '%s ' . $shopengine_rating_plural_label, $review_count, 'shopengine' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a> |
| 52 | <?php // phpcs:enable ?> |
| 53 | <?php endif ?> |
| 54 | </div> |
| 55 | <?php |
| 56 | endif; |
| 57 | endif; |
| 58 | ?> |
| 59 | </div> |