Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Site Reviews: This is a custom shortcode replacement for the Woo Rating module
- *
- * [glsr_woo_product_rating]
- *
- * Shortcode options:
- * - display_if_empty: true|false
- */
- add_shortcode('glsr_woo_product_rating', function ($atts) {
- if (!function_exists('wc_get_product') // make sure Woocommerce is activated
- || !function_exists('glsr') // make sure Site Reviews is activated
- || !function_exists('glsr_get_ratings')
- || !function_exists('glsr_get_option')
- || !function_exists('glsr_star_rating')) {
- return;
- }
- global $product;
- $wooEnabled = 'yes' === get_option('woocommerce_enable_reviews', 'yes');
- $addonEnabled = glsr_get_option('settings.addons.woocommerce.enabled', false, 'bool');
- if (!$wooEnabled || !$addonEnabled) {
- return;
- }
- $atts = wp_parse_args($atts, [
- 'display_if_empty' => true,
- ]);
- $ratings = glsr_get_ratings(['assigned_posts' => 'post_id']);
- if (wp_validate_boolean($atts['display_if_empty']) && $ratings->reviews < 1) {
- return;
- }
- ob_start();
- ?>
- <div class="et_pb_wc_rating et_pb_wc_rating_layout_inline">
- <div class="woocommerce-product-rating <?= glsr('Modules\Style')->styleClasses(); ?>">
- <?= glsr_star_rating($ratings->average); ?>
- <?php if ($product && $product->get_reviews_allowed()) : ?>
- <a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?= sprintf(_n('%s customer review', '%s customer reviews', $ratings->reviews, 'woocommerce'), '<span class="count">'.esc_html($ratings->reviews).'</span>'); ?>)</a>
- <?php endif; ?>
- </div>
- </div>
- <?php
- return ob_get_clean();
- });
Add Comment
Please, Sign In to add comment