PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.1
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.1
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / templates / modules / advanced-reviews / reviews.php

reviews.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.8.1, at templates/modules/advanced-reviews/reviews.php

403 lines 14.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Template for advanced reviews items.
5 *
6 * $args module settings.
7 *
8 * @since 1.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! isset( $args[ 'product' ] ) ) {
16 return;
17 }
18
19 $product = $args[ 'product' ];
20 $product_id = $product->get_id();
21 $review_count = $product->get_review_count();
22 $average = $product->get_average_rating();
23
24 // Title tag
25 $title_tag = $args[ 'title_tag' ];
26
27 // Dropdown sort
28 $default_sorting = $args[ 'default_sorting' ];
29 $sort_orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : $default_sorting; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
30
31 // Reviews bars rating
32 $bars_data = $args['bars_data']; ?>
33
34 <section id="reviews" class="merchant-adv-reviews products<?php echo ( $args[ 'hide_title' ] ) ? ' hide-title' : ''; ?>">
35 <?php
36 if ( ! $args[ 'hide_title' ] ) :
37
38 echo wp_kses_post(
39 sprintf(
40 '<%1$s id="reviews-stars" class="merchant-adv-reviews-title">%2$s</%1$s>',
41 $title_tag,
42 esc_html( Merchant_Translator::translate( $args[ 'title' ] ) )
43 )
44 );
45
46 ?>
47
48 <p class="merchant-adv-reviews-desc">
49 <?php echo esc_html( Merchant_Translator::translate( $args[ 'description' ] ) ); ?>
50 </p>
51
52 <?php endif; ?>
53
54 <div class="merchant-adv-reviews-header">
55 <div class="mrc-row mrc-columns-no-gutter">
56 <div class="mrc-col mrc-left-col">
57
58 <?php if ( $args['ratings_enabled'] && $bars_data['total'] > 0 ) : ?>
59 <div class="merchant-adv-reviews-rating-wrapper">
60 <strong class="merchant-adv-reviews-rating"><?php echo esc_html( $average ); ?></strong>
61 <div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated <?php echo esc_attr( $average ); ?> out of 5">
62 <span style="width: <?php echo esc_attr( ( ( $average / 5 ) * 100 ) ); ?>%;">
63 <?php
64 /* translators: %s is average rating value */
65 $rating_text = sprintf( __( 'Rated %s out of 5 based on customer ratings.', 'merchant' ), $average );
66 echo esc_html( $rating_text );
67 ?>
68 </span>
69 </div>
70 </div>
71 <?php endif; ?>
72
73 <p class="merchant-adv-reviews-total">
74 <?php
75 if ( $review_count > 0 ) {
76 /* translators: %s is review count */
77 $review_count_text = sprintf( _nx( '%s Review', '%s Reviews', $review_count, 'review count', 'merchant' ), number_format_i18n( $review_count ) );
78 echo esc_html( $review_count_text );
79 } else {
80 echo esc_html__( 'Be the first to leave a review.', 'merchant' );
81 }
82 ?>
83 </p>
84
85 <?php if ( $args['ratings_enabled'] && $bars_data[ 'total' ] > 0 ) : ?>
86 <div class="merchant-star-rating-bars">
87 <div class="merchant-star-rating-bar-item">
88 <p class="item-rating"><?php echo esc_html__( '5 Stars', 'merchant' ); ?></p>
89 <div class="item-bar">
90 <div class="item-bar-inner" style="width: <?php echo esc_attr( $bars_data[ '5-stars-percent' ] ); ?>%;"></div>
91 </div>
92 <p class="item-qty">
93 <?php
94 /* translators: %s is stars quantity */
95 $five_star_text = sprintf( esc_html__( '(%s)', 'merchant' ), $bars_data[ '5-stars' ] );
96 echo esc_html( $five_star_text );
97 ?>
98 </p>
99 </div>
100 <div class="merchant-star-rating-bar-item">
101 <p class="item-rating"><?php echo esc_html__( '4 Stars', 'merchant' ); ?></p>
102 <div class="item-bar">
103 <div class="item-bar-inner" style="width: <?php echo esc_attr( $bars_data[ '4-stars-percent' ] ); ?>%;"></div>
104 </div>
105 <p class="item-qty">
106 <?php
107 /* translators: %s is stars quantity */
108 $four_star_text = sprintf( esc_html__( '(%s)', 'merchant' ), $bars_data[ '4-stars' ] );
109 echo esc_html( $four_star_text );
110 ?>
111 </p>
112 </div>
113 <div class="merchant-star-rating-bar-item">
114 <p class="item-rating"><?php echo esc_html__( '3 Stars', 'merchant' ); ?></p>
115 <div class="item-bar">
116 <div class="item-bar-inner" style="width: <?php echo esc_attr( $bars_data[ '3-stars-percent' ] ); ?>%;"></div>
117 </div>
118 <p class="item-qty">
119 <?php
120 /* translators: %s is stars quantity */
121 $three_star_text = sprintf( esc_html__( '(%s)', 'merchant' ), $bars_data[ '3-stars' ] );
122 echo esc_html( $three_star_text );
123 ?>
124 </p>
125 </div>
126 <div class="merchant-star-rating-bar-item">
127 <p class="item-rating"><?php echo esc_html__( '2 Stars', 'merchant' ); ?></p>
128 <div class="item-bar">
129 <div class="item-bar-inner" style="width: <?php echo esc_attr( $bars_data[ '2-stars-percent' ] ); ?>%;"></div>
130 </div>
131 <p class="item-qty">
132 <?php
133 /* translators: %s is stars quantity */
134 $two_star_text = sprintf( esc_html__( '(%s)', 'merchant' ), $bars_data[ '2-stars' ] );
135 echo esc_html( $two_star_text );
136 ?>
137 </p>
138 </div>
139 <div class="merchant-star-rating-bar-item">
140 <p class="item-rating"><?php echo esc_html__( '1 Star', 'merchant' ); ?></p>
141 <div class="item-bar">
142 <div class="item-bar-inner" style="width: <?php echo esc_attr( $bars_data[ '1-stars-percent' ] ); ?>%;"></div>
143 </div>
144 <p class="item-qty">
145 <?php
146 /* translators: %s is stars quantity */
147 $one_star_text = sprintf( esc_html__( '(%s)', 'merchant' ), $bars_data[ '1-stars' ] );
148 echo esc_html( $one_star_text );
149 ?>
150 </p>
151 </div>
152 </div>
153 <?php endif; ?>
154
155 </div>
156 <div class="mrc-col mrc-right-col">
157 <a href="#" class="merchant-adv-review-write-button"><?php echo esc_html__( 'Write a Review', 'merchant' ); ?></a>
158
159 <?php if ( $review_count > 0 ) : ?>
160 <form class="merchant-reviews-orderby-form" method="get" action="<?php echo esc_url( get_the_permalink( $product_id ) ); ?>#reviews-stars">
161 <label for="orderby"><?php echo esc_html__( 'Sort by:', 'merchant' ); ?></label>
162 <select class="merchant-reviews-orderby" name="orderby" onChange="this.parentNode.submit();">
163 <option value="newest"<?php echo selected( $sort_orderby, 'newest' ); ?>><?php echo esc_html__( 'Newest', 'merchant' ); ?></option>
164 <option value="oldest"<?php echo selected( $sort_orderby, 'oldest' ); ?>><?php echo esc_html__( 'Oldest', 'merchant' ); ?></option>
165 <option value="top-rated"<?php echo selected( $sort_orderby, 'top-rated' ); ?>><?php echo esc_html__( 'Top rated', 'merchant' ); ?></option>
166 <option value="low-rated"<?php echo selected( $sort_orderby, 'low-rated' ); ?>><?php echo esc_html__( 'Low rated', 'merchant' ); ?></option>
167 </select>
168 </form>
169 <?php endif; ?>
170 </div>
171 </div>
172 </div>
173 <div class="merchant-adv-reviews-body">
174
175 <?php
176 if ( $args['comments_open'] ) :
177 // Get comments args
178 $comments_args = array(
179 'post_id' => $product_id,
180 'number' => get_option( 'page_comments' ) ? get_option( 'comments_per_page' ) : '',
181 );
182
183 // Pagination?
184 $cpages = 0;
185 if ( get_option( 'page_comments' ) ) {
186 $cpaged = get_query_var( 'cpage' );
187
188 $cpages = count( get_comments( array(
189 'post_id' => $product_id,
190 'fields' => 'ids',
191 ) ) );
192
193 $cpages = $cpages / get_option( 'comments_per_page' );
194
195 $comments_args[ 'paged' ] = empty( $cpaged ) ? 1 : $cpaged;
196 }
197
198 // Orderby
199 switch ( $sort_orderby ) {
200 case 'newest':
201 $comments_args[ 'order' ] = 'DESC';
202 $comments_args[ 'orderby' ] = 'comment_date_gmt';
203 break;
204
205 case 'oldest':
206 $comments_args[ 'order' ] = 'ASC';
207 $comments_args[ 'orderby' ] = 'comment_date_gmt';
208 break;
209
210 case 'top-rated':
211 $comments_args[ 'order' ] = 'DESC';
212 $comments_args[ 'orderby' ] = 'meta_value_num';
213 // phpcs:disable
214 $comments_args[ 'meta_key' ] = 'rating';
215 // phpcs:enable
216 break;
217
218 case 'low-rated':
219 $comments_args[ 'order' ] = 'ASC';
220 $comments_args[ 'orderby' ] = 'meta_value_num';
221 // phpcs:disable
222 $comments_args[ 'meta_key' ] = 'rating';
223 // phpcs:enable
224 break;
225 }
226
227 /**
228 * Hook 'merchant_wc_reviews_advanced_sorting_args'
229 *
230 * @since 1.0
231 */
232 $_comments = isset($args['comments']) ? $args['comments'] : get_comments( apply_filters( 'merchant_wc_reviews_advanced_sorting_args',$comments_args ) ); ?>
233
234 <div id="comments">
235 <?php if ( count( $_comments ) > 0 ) : ?>
236 <div class="merchant-reviews-list-wrapper">
237
238 <?php
239 foreach ( $_comments as $_comment ) :
240 if ( '1' === $_comment->comment_approved ) :
241 ?>
242
243 <div id="comment-<?php echo esc_attr( $_comment->comment_ID ); ?>" class="merchant-reviews-list-item">
244 <div class="mrc-row mrc-columns-no-gutter">
245 <div class="mrc-col">
246 <div class="merchant-reviews-author-wrapper">
247
248 <?php
249 $comment_rating_value = isset( $args['comment_rating'] ) ? $args['comment_rating'] : get_comment_meta( $_comment->comment_ID, 'rating', true ); ?>
250
251 <?php if( wc_review_ratings_enabled() ) : ?>
252 <div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated <?php echo esc_attr( $comment_rating_value ); ?>.00 out of 5">
253 <span style="width: <?php echo esc_attr( ( ( $comment_rating_value / 5 ) * 100 ) ); ?>%;">
254 <?php
255 /* translators: %s is average rating value */
256 $comment_rating_text = sprintf( __( 'Rated %s out of 5 based on customer ratings.', 'merchant' ), $comment_rating_value );
257 echo esc_html( $comment_rating_text ); ?>
258 </span>
259 </div>
260 <?php endif; ?>
261
262 <strong class="merchant-review-author">
263 <?php echo esc_html( get_comment_author( $_comment ) ); ?>
264
265 <?php
266 /**
267 * Verified owner
268 */
269 $verified = wc_review_is_from_verified_owner( $_comment->comment_ID );
270 if ( 'yes' === get_option( 'woocommerce_review_rating_verification_label' ) && $verified ) {
271 echo '<em class="woocommerce-review__verified verified">'. esc_attr__( ' — verified owner', 'merchant' ) . '</em> ';
272 } ?>
273 </strong>
274 </div>
275 </div>
276 <div class="mrc-col-3 merchant-review-date-wrapper">
277 <time class="merchant-review-date" datetime="<?php echo esc_attr( get_comment_date( 'c', $_comment ) ); ?>"><?php echo esc_html( get_comment_date( 'F j, Y', $_comment ) ); ?></time>
278 </div>
279 </div>
280 <div class="mrc-row mrc-columns-no-gutter">
281 <div class="mrc-col">
282 <div class="merchant-review-content">
283 <?php
284
285 /**
286 * Hook 'woocommerce_review_before_comment_text'
287 *
288 * @since 1.0
289 */
290 do_action( 'woocommerce_review_before_comment_text', $_comment ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Ensure compatibility with WooCommerce plugins
291
292 if ( isset( $args['comment_text'] ) ) {
293 echo wp_kses_post( $args['comment_text'] );
294 } else {
295 comment_text( $_comment );
296 }
297
298 /**
299 * Hook 'woocommerce_review_after_comment_text'
300 *
301 * @since 1.0
302 */
303 do_action( 'woocommerce_review_after_comment_text', $_comment ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Ensure compatibility with WooCommerce plugins
304 ?>
305 </div>
306 </div>
307 </div>
308 </div>
309
310 <?php elseif( isset( $_GET['unapproved'] ) && $_comment->comment_ID === $_GET['unapproved'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
311
312 <div id="comment-<?php echo esc_attr( $_comment->comment_ID ); ?>" class="merchant-reviews-list-item">
313 <div class="row">
314 <div class="col-12">
315 <div class="d-flex align-items-center">
316
317 <?php
318 $comment_rating_value = get_comment_meta( $_comment->comment_ID, 'rating', true ); ?>
319
320 <?php if( wc_review_ratings_enabled() ) : ?>
321 <div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated <?php echo esc_attr( $comment_rating_value ); ?>.00 out of 5">
322 <span style="width: <?php echo esc_attr( ( ( $comment_rating_value / 5 ) * 100 ) ); ?>%;">
323 <?php
324 /* translators: %s is average rating value */
325 $comment_rating_text = sprintf( __( 'Rated %s out of 5 based on customer ratings.', 'merchant' ), $comment_rating_value );
326 echo esc_html( $comment_rating_text ); ?>
327 </span>
328 </div>
329 <?php endif; ?>
330
331 <strong class="merchant-review-author">
332 <?php echo esc_html( get_comment_author( $_comment ) ); ?>
333
334 <?php
335 /**
336 * Verified owner
337 */
338 $verified = wc_review_is_from_verified_owner( $_comment->comment_ID );
339 if ( 'yes' === get_option( 'woocommerce_review_rating_verification_label' ) && $verified ) {
340 echo '<em class="woocommerce-review__verified verified">'. esc_attr__( ' — verified owner', 'merchant' ) . '</em> ';
341 } ?>
342 </strong>
343 </div>
344 <br>
345 <em><?php echo esc_html__( 'Your review is awaiting approval.', 'merchant' ); ?></em>
346 </div>
347 </div>
348 </div>
349
350 <?php endif;
351 endforeach; ?>
352
353 </div>
354
355 <?php else : ?>
356 <p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'merchant' ); ?></p>
357 <?php endif; ?>
358 </div>
359
360 <?php endif; ?>
361
362 </div>
363 <?php if ( isset( $comments ) && count( $comments ) > 0 ) {
364 echo '<div class="merchant-adv-reviews-footer">';
365
366 if ( $cpages > 1 && get_option( 'page_comments' ) ) {
367 echo '<nav class="woocommerce-pagination merchant-pagination merchant-adv-reviews-pagination">';
368
369 merchant_get_template_part( 'modules/advanced-reviews', 'pagination-links', array_merge(
370 $args,
371 array(
372 'pagination_args' => array(
373 'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
374 'next_text' => is_rtl() ? '&larr;' : '&rarr;',
375 'type' => 'list',
376 ),
377 'cpages' => $cpages,
378 'product_id' => $product_id,
379 )
380 ) );
381
382 echo '</nav>';
383
384 /**
385 * Hook 'merchant_after_shop_reviews_adv_pagination'
386 *
387 * @since 1.0
388 */
389 do_action( 'merchant_after_shop_reviews_adv_pagination' );
390 }
391
392 echo '</div>';
393 } ?>
394 </section>
395
396 <?php
397 /**
398 * Hook 'merchant_after_adv_reviews_section'
399 *
400 * @since 1.0
401 */
402 do_action( 'merchant_after_adv_reviews_section' ); ?>
403