| 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( $args[ 'title' ] ) |
| 43 |
) |
| 44 |
); |
| 45 |
|
| 46 |
?> |
| 47 |
|
| 48 |
<p class="merchant-adv-reviews-desc"> |
| 49 |
<?php echo esc_html( $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 |
$comments_args[ 'meta_key' ] = 'rating'; |
| 214 |
break; |
| 215 |
|
| 216 |
case 'low-rated': |
| 217 |
$comments_args[ 'order' ] = 'ASC'; |
| 218 |
$comments_args[ 'orderby' ] = 'meta_value_num'; |
| 219 |
$comments_args[ 'meta_key' ] = 'rating'; |
| 220 |
break; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Hook 'merchant_wc_reviews_advanced_sorting_args' |
| 225 |
* |
| 226 |
* @since 1.0 |
| 227 |
*/ |
| 228 |
$_comments = isset($args['comments']) ? $args['comments'] : get_comments( apply_filters( 'merchant_wc_reviews_advanced_sorting_args',$comments_args ) ); ?> |
| 229 |
|
| 230 |
<div id="comments"> |
| 231 |
<?php if ( count( $_comments ) > 0 ) : ?> |
| 232 |
<div class="merchant-reviews-list-wrapper"> |
| 233 |
|
| 234 |
<?php |
| 235 |
foreach ( $_comments as $_comment ) : |
| 236 |
if ( '1' === $_comment->comment_approved ) : |
| 237 |
?> |
| 238 |
|
| 239 |
<div id="comment-<?php echo esc_attr( $_comment->comment_ID ); ?>" class="merchant-reviews-list-item"> |
| 240 |
<div class="mrc-row mrc-columns-no-gutter"> |
| 241 |
<div class="mrc-col"> |
| 242 |
<div class="merchant-reviews-author-wrapper"> |
| 243 |
|
| 244 |
<?php |
| 245 |
$comment_rating_value = isset( $args['comment_rating'] ) ? $args['comment_rating'] : get_comment_meta( $_comment->comment_ID, 'rating', true ); ?> |
| 246 |
|
| 247 |
<?php if( wc_review_ratings_enabled() ) : ?> |
| 248 |
<div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated <?php echo esc_attr( $comment_rating_value ); ?>.00 out of 5"> |
| 249 |
<span style="width: <?php echo esc_attr( ( ( $comment_rating_value / 5 ) * 100 ) ); ?>%;"> |
| 250 |
<?php |
| 251 |
/* translators: %s is average rating value */ |
| 252 |
$comment_rating_text = sprintf( __( 'Rated %s out of 5 based on customer ratings.', 'merchant' ), $comment_rating_value ); |
| 253 |
echo esc_html( $comment_rating_text ); ?> |
| 254 |
</span> |
| 255 |
</div> |
| 256 |
<?php endif; ?> |
| 257 |
|
| 258 |
<strong class="merchant-review-author"> |
| 259 |
<?php echo esc_html( get_comment_author( $_comment ) ); ?> |
| 260 |
|
| 261 |
<?php |
| 262 |
/** |
| 263 |
* Verified owner |
| 264 |
*/ |
| 265 |
$verified = wc_review_is_from_verified_owner( $_comment->comment_ID ); |
| 266 |
if ( 'yes' === get_option( 'woocommerce_review_rating_verification_label' ) && $verified ) { |
| 267 |
echo '<em class="woocommerce-review__verified verified">'. esc_attr__( ' — verified owner', 'merchant' ) . '</em> '; |
| 268 |
} ?> |
| 269 |
</strong> |
| 270 |
</div> |
| 271 |
</div> |
| 272 |
<div class="mrc-col-3 merchant-review-date-wrapper"> |
| 273 |
<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> |
| 274 |
</div> |
| 275 |
</div> |
| 276 |
<div class="mrc-row mrc-columns-no-gutter"> |
| 277 |
<div class="mrc-col"> |
| 278 |
<div class="merchant-review-content"> |
| 279 |
<?php |
| 280 |
|
| 281 |
/** |
| 282 |
* Hook 'woocommerce_review_before_comment_text' |
| 283 |
* |
| 284 |
* @since 1.0 |
| 285 |
*/ |
| 286 |
do_action( 'woocommerce_review_before_comment_text', $_comment ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Ensure compatibility with WooCommerce plugins |
| 287 |
|
| 288 |
if ( isset( $args['comment_text'] ) ) { |
| 289 |
echo wp_kses_post( $args['comment_text'] ); |
| 290 |
} else { |
| 291 |
comment_text( $_comment ); |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Hook 'woocommerce_review_after_comment_text' |
| 296 |
* |
| 297 |
* @since 1.0 |
| 298 |
*/ |
| 299 |
do_action( 'woocommerce_review_after_comment_text', $_comment ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Ensure compatibility with WooCommerce plugins |
| 300 |
?> |
| 301 |
</div> |
| 302 |
</div> |
| 303 |
</div> |
| 304 |
</div> |
| 305 |
|
| 306 |
<?php elseif( isset( $_GET['unapproved'] ) && $_comment->comment_ID === $_GET['unapproved'] ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?> |
| 307 |
|
| 308 |
<div id="comment-<?php echo esc_attr( $_comment->comment_ID ); ?>" class="merchant-reviews-list-item"> |
| 309 |
<div class="row"> |
| 310 |
<div class="col-12"> |
| 311 |
<div class="d-flex align-items-center"> |
| 312 |
|
| 313 |
<?php |
| 314 |
$comment_rating_value = get_comment_meta( $_comment->comment_ID, 'rating', true ); ?> |
| 315 |
|
| 316 |
<?php if( wc_review_ratings_enabled() ) : ?> |
| 317 |
<div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated <?php echo esc_attr( $comment_rating_value ); ?>.00 out of 5"> |
| 318 |
<span style="width: <?php echo esc_attr( ( ( $comment_rating_value / 5 ) * 100 ) ); ?>%;"> |
| 319 |
<?php |
| 320 |
/* translators: %s is average rating value */ |
| 321 |
$comment_rating_text = sprintf( __( 'Rated %s out of 5 based on customer ratings.', 'merchant' ), $comment_rating_value ); |
| 322 |
echo esc_html( $comment_rating_text ); ?> |
| 323 |
</span> |
| 324 |
</div> |
| 325 |
<?php endif; ?> |
| 326 |
|
| 327 |
<strong class="merchant-review-author"> |
| 328 |
<?php echo esc_html( get_comment_author( $_comment ) ); ?> |
| 329 |
|
| 330 |
<?php |
| 331 |
/** |
| 332 |
* Verified owner |
| 333 |
*/ |
| 334 |
$verified = wc_review_is_from_verified_owner( $_comment->comment_ID ); |
| 335 |
if ( 'yes' === get_option( 'woocommerce_review_rating_verification_label' ) && $verified ) { |
| 336 |
echo '<em class="woocommerce-review__verified verified">'. esc_attr__( ' — verified owner', 'merchant' ) . '</em> '; |
| 337 |
} ?> |
| 338 |
</strong> |
| 339 |
</div> |
| 340 |
<br> |
| 341 |
<em><?php echo esc_html__( 'Your review is awaiting approval.', 'merchant' ); ?></em> |
| 342 |
</div> |
| 343 |
</div> |
| 344 |
</div> |
| 345 |
|
| 346 |
<?php endif; |
| 347 |
endforeach; ?> |
| 348 |
|
| 349 |
</div> |
| 350 |
|
| 351 |
<?php else : ?> |
| 352 |
<p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'merchant' ); ?></p> |
| 353 |
<?php endif; ?> |
| 354 |
</div> |
| 355 |
|
| 356 |
<?php endif; ?> |
| 357 |
|
| 358 |
</div> |
| 359 |
<?php if ( isset( $comments ) && count( $comments ) > 0 ) { |
| 360 |
echo '<div class="merchant-adv-reviews-footer">'; |
| 361 |
|
| 362 |
if ( $cpages > 1 && get_option( 'page_comments' ) ) { |
| 363 |
echo '<nav class="woocommerce-pagination merchant-pagination merchant-adv-reviews-pagination">'; |
| 364 |
|
| 365 |
merchant_get_template_part( 'modules/advanced-reviews', 'pagination-links', array_merge( |
| 366 |
$args, |
| 367 |
array( |
| 368 |
'pagination_args' => array( |
| 369 |
'prev_text' => is_rtl() ? '→' : '←', |
| 370 |
'next_text' => is_rtl() ? '←' : '→', |
| 371 |
'type' => 'list' |
| 372 |
), |
| 373 |
'cpages' => $cpages, |
| 374 |
'product_id' => $product_id |
| 375 |
) |
| 376 |
) ); |
| 377 |
|
| 378 |
echo '</nav>'; |
| 379 |
|
| 380 |
/** |
| 381 |
* Hook 'merchant_after_shop_reviews_adv_pagination' |
| 382 |
* |
| 383 |
* @since 1.0 |
| 384 |
*/ |
| 385 |
do_action( 'merchant_after_shop_reviews_adv_pagination' ); |
| 386 |
} |
| 387 |
|
| 388 |
echo '</div>'; |
| 389 |
} ?> |
| 390 |
</section> |
| 391 |
|
| 392 |
<?php |
| 393 |
/** |
| 394 |
* Hook 'merchant_after_adv_reviews_section' |
| 395 |
* |
| 396 |
* @since 1.0 |
| 397 |
*/ |
| 398 |
do_action( 'merchant_after_adv_reviews_section' ); ?> |
| 399 |
|