single-product-reviews.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * @author WooThemes
  15. * @package WooCommerce/Templates
  16. * @version 3.2.0
  17. */
  18. if ( ! defined( 'ABSPATH' ) ) {
  19. exit; // Exit if accessed directly
  20. }
  21. global $product;
  22. if ( ! comments_open() ) {
  23. return;
  24. }
  25. ?>
  26. <div id="reviews" class="woocommerce-Reviews">
  27. <div id="comments">
  28. <h2 class="woocommerce-Reviews-title"><?php
  29. if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_review_count() ) ) {
  30. /* translators: 1: reviews count 2: product name */
  31. printf( 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>' );
  32. } else {
  33. _e( 'Reviews', 'woocommerce' );
  34. }
  35. ?></h2>
  36. <?php if ( have_comments() ) : ?>
  37. <ol class="commentlist">
  38. <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) ); ?>
  39. </ol>
  40. <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
  41. echo '<nav class="woocommerce-pagination">';
  42. paginate_comments_links( apply_filters( 'woocommerce_comment_pagination_args', array(
  43. 'prev_text' => '&larr;',
  44. 'next_text' => '&rarr;',
  45. 'type' => 'list',
  46. ) ) );
  47. echo '</nav>';
  48. endif; ?>
  49. <?php else : ?>
  50. <p class="woocommerce-noreviews"><?php _e( 'There are no reviews yet.', 'woocommerce' ); ?></p>
  51. <?php endif; ?>
  52. </div>
  53. <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>
  54. <div id="review_form_wrapper">
  55. <div id="review_form">
  56. <?php
  57. $commenter = wp_get_current_commenter();
  58. $comment_form = array(
  59. 'title_reply' => have_comments() ? __( 'Add a review', 'woocommerce' ) : sprintf( __( 'Be the first to review &ldquo;%s&rdquo;', 'woocommerce' ), get_the_title() ),
  60. 'title_reply_to' => __( 'Leave a Reply to %s', 'woocommerce' ),
  61. 'title_reply_before' => '<span id="reply-title" class="comment-reply-title">',
  62. 'title_reply_after' => '</span>',
  63. 'comment_notes_after' => '',
  64. 'fields' => array(
  65. 'author' => '<p class="comment-form-author">' . '<label for="author">' . esc_html__( 'Name', 'woocommerce' ) . '&nbsp;<span class="required">*</span></label> ' .
  66. '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" required /></p>',
  67. 'email' => '<p class="comment-form-email"><label for="email">' . esc_html__( 'Email', 'woocommerce' ) . '&nbsp;<span class="required">*</span></label> ' .
  68. '<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-required="true" required /></p>',
  69. ),
  70. 'label_submit' => __( 'Submit', 'woocommerce' ),
  71. 'logged_in_as' => '',
  72. 'comment_field' => '',
  73. );
  74. if ( $account_page_url = wc_get_page_permalink( 'myaccount' ) ) {
  75. $comment_form['must_log_in'] = '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a review.', 'woocommerce' ), esc_url( $account_page_url ) ) . '</p>';
  76. }
  77. if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
  78. $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . '</label><select name="rating" id="rating" aria-required="true" required>
  79. <option value="">' . esc_html__( 'Rate&hellip;', 'woocommerce' ) . '</option>
  80. <option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option>
  81. <option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option>
  82. <option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option>
  83. <option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
  84. <option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option>
  85. </select></div>';
  86. }
  87. $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" aria-required="true" required></textarea></p>';
  88. comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
  89. ?>
  90. </div>
  91. </div>
  92. <?php else : ?>
  93. <p class="woocommerce-verification-required"><?php _e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>
  94. <?php endif; ?>
  95. <div class="clear"></div>
  96. </div>