Нема описа

single-product-reviews.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Display single product reviews (comments)
  4. *
  5. * This template can be overridden by copying it to yourtheme/woocommerce/single-product-reviews.php.
  6. *
  7. * HOWEVER, on occasion WooCommerce will need to update template files and you
  8. * (the theme developer) will need to copy the new files to your theme to
  9. * maintain compatibility. We try to do this as little as possible, but it does
  10. * happen. When this occurs the version of the template file will be bumped and
  11. * the readme will list any important changes.
  12. *
  13. * @see https://docs.woocommerce.com/document/template-structure/
  14. * @package WooCommerce\Templates
  15. * @version 4.3.0
  16. */
  17. defined( 'ABSPATH' ) || exit;
  18. global $product;
  19. if ( ! comments_open() ) {
  20. return;
  21. }
  22. ?>
  23. <div id="reviews" class="woocommerce-Reviews">
  24. <div id="comments">
  25. <h2 class="woocommerce-Reviews-title">
  26. <?php
  27. $count = $product->get_review_count();
  28. if ( $count && wc_review_ratings_enabled() ) {
  29. /* translators: 1: reviews count 2: product name */
  30. $reviews_title = sprintf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );
  31. echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $product ); // WPCS: XSS ok.
  32. } else {
  33. esc_html_e( 'Reviews', 'woocommerce' );
  34. }
  35. ?>
  36. </h2>
  37. <?php if ( have_comments() ) : ?>
  38. <ol class="commentlist">
  39. <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) ); ?>
  40. </ol>
  41. <?php
  42. if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
  43. echo '<nav class="woocommerce-pagination">';
  44. paginate_comments_links(
  45. apply_filters(
  46. 'woocommerce_comment_pagination_args',
  47. array(
  48. 'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
  49. 'next_text' => is_rtl() ? '&larr;' : '&rarr;',
  50. 'type' => 'list',
  51. )
  52. )
  53. );
  54. echo '</nav>';
  55. endif;
  56. ?>
  57. <?php else : ?>
  58. <p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p>
  59. <?php endif; ?>
  60. </div>
  61. <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>
  62. <div id="review_form_wrapper">
  63. <div id="review_form">
  64. <?php
  65. $commenter = wp_get_current_commenter();
  66. $comment_form = array(
  67. /* translators: %s is product title */
  68. 'title_reply' => have_comments() ? esc_html__( 'Add a review', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review &ldquo;%s&rdquo;', 'woocommerce' ), get_the_title() ),
  69. /* translators: %s is product title */
  70. 'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'woocommerce' ),
  71. 'title_reply_before' => '<span id="reply-title" class="comment-reply-title">',
  72. 'title_reply_after' => '</span>',
  73. 'comment_notes_after' => '',
  74. 'label_submit' => esc_html__( 'Submit', 'woocommerce' ),
  75. 'logged_in_as' => '',
  76. 'comment_field' => '',
  77. );
  78. $name_email_required = (bool) get_option( 'require_name_email', 1 );
  79. $fields = array(
  80. 'author' => array(
  81. 'label' => __( 'Name', 'woocommerce' ),
  82. 'type' => 'text',
  83. 'value' => $commenter['comment_author'],
  84. 'required' => $name_email_required,
  85. ),
  86. 'email' => array(
  87. 'label' => __( 'Email', 'woocommerce' ),
  88. 'type' => 'email',
  89. 'value' => $commenter['comment_author_email'],
  90. 'required' => $name_email_required,
  91. ),
  92. );
  93. $comment_form['fields'] = array();
  94. foreach ( $fields as $key => $field ) {
  95. $field_html = '<p class="comment-form-' . esc_attr( $key ) . '">';
  96. $field_html .= '<label for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] );
  97. if ( $field['required'] ) {
  98. $field_html .= '&nbsp;<span class="required">*</span>';
  99. }
  100. $field_html .= '</label><input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="' . esc_attr( $field['type'] ) . '" value="' . esc_attr( $field['value'] ) . '" size="30" ' . ( $field['required'] ? 'required' : '' ) . ' /></p>';
  101. $comment_form['fields'][ $key ] = $field_html;
  102. }
  103. $account_page_url = wc_get_page_permalink( 'myaccount' );
  104. if ( $account_page_url ) {
  105. /* translators: %s opening and closing link tags respectively */
  106. $comment_form['must_log_in'] = '<p class="must-log-in">' . sprintf( esc_html__( 'You must be %1$slogged in%2$s to post a review.', 'woocommerce' ), '<a href="' . esc_url( $account_page_url ) . '">', '</a>' ) . '</p>';
  107. }
  108. if ( wc_review_ratings_enabled() ) {
  109. $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . ( wc_review_ratings_required() ? '&nbsp;<span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required>
  110. <option value="">' . esc_html__( 'Rate&hellip;', 'woocommerce' ) . '</option>
  111. <option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option>
  112. <option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option>
  113. <option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option>
  114. <option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
  115. <option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option>
  116. </select></div>';
  117. }
  118. $comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . '&nbsp;<span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" required></textarea></p>';
  119. comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
  120. ?>
  121. </div>
  122. </div>
  123. <?php else : ?>
  124. <p class="woocommerce-verification-required"><?php esc_html_e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>
  125. <?php endif; ?>
  126. <div class="clear"></div>
  127. </div>