auth
2 years ago
block-notices
2 years ago
cart
2 years ago
checkout
2 years ago
emails
2 years ago
global
2 years ago
loop
2 years ago
myaccount
2 years ago
notices
2 years ago
order
2 years ago
parts
2 years ago
single-product
2 years ago
templates
2 years ago
archive-product.php
2 years ago
content-product-cat.php
2 years ago
content-product.php
2 years ago
content-single-product.php
2 years ago
content-widget-price-filter.php
2 years ago
content-widget-product.php
2 years ago
content-widget-reviews.php
2 years ago
product-searchform.php
2 years ago
single-product-reviews.php
2 years ago
single-product.php
2 years ago
taxonomy-product-attribute.php
2 years ago
taxonomy-product-cat.php
2 years ago
taxonomy-product-tag.php
2 years ago
single-product-reviews.php
146 lines
| 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://woo.com/document/template-structure/ |
| 14 | * @package WooCommerce\Templates |
| 15 | * @version 4.3.0 |
| 16 | */ |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | global $product; |
| 21 | |
| 22 | if ( ! comments_open() ) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | ?> |
| 27 | <div id="reviews" class="woocommerce-Reviews"> |
| 28 | <div id="comments"> |
| 29 | <h2 class="woocommerce-Reviews-title"> |
| 30 | <?php |
| 31 | $count = $product->get_review_count(); |
| 32 | if ( $count && wc_review_ratings_enabled() ) { |
| 33 | /* translators: 1: reviews count 2: product name */ |
| 34 | $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>' ); |
| 35 | echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $product ); // WPCS: XSS ok. |
| 36 | } else { |
| 37 | esc_html_e( 'Reviews', 'woocommerce' ); |
| 38 | } |
| 39 | ?> |
| 40 | </h2> |
| 41 | |
| 42 | <?php if ( have_comments() ) : ?> |
| 43 | <ol class="commentlist"> |
| 44 | <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) ); ?> |
| 45 | </ol> |
| 46 | |
| 47 | <?php |
| 48 | if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : |
| 49 | echo '<nav class="woocommerce-pagination">'; |
| 50 | paginate_comments_links( |
| 51 | apply_filters( |
| 52 | 'woocommerce_comment_pagination_args', |
| 53 | array( |
| 54 | 'prev_text' => is_rtl() ? '→' : '←', |
| 55 | 'next_text' => is_rtl() ? '←' : '→', |
| 56 | 'type' => 'list', |
| 57 | ) |
| 58 | ) |
| 59 | ); |
| 60 | echo '</nav>'; |
| 61 | endif; |
| 62 | ?> |
| 63 | <?php else : ?> |
| 64 | <p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p> |
| 65 | <?php endif; ?> |
| 66 | </div> |
| 67 | |
| 68 | <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?> |
| 69 | <div id="review_form_wrapper"> |
| 70 | <div id="review_form"> |
| 71 | <?php |
| 72 | $commenter = wp_get_current_commenter(); |
| 73 | $comment_form = array( |
| 74 | /* translators: %s is product title */ |
| 75 | 'title_reply' => have_comments() ? esc_html__( 'Add a review', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review “%s”', 'woocommerce' ), get_the_title() ), |
| 76 | /* translators: %s is product title */ |
| 77 | 'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'woocommerce' ), |
| 78 | 'title_reply_before' => '<span id="reply-title" class="comment-reply-title">', |
| 79 | 'title_reply_after' => '</span>', |
| 80 | 'comment_notes_after' => '', |
| 81 | 'label_submit' => esc_html__( 'Submit', 'woocommerce' ), |
| 82 | 'logged_in_as' => '', |
| 83 | 'comment_field' => '', |
| 84 | ); |
| 85 | |
| 86 | $name_email_required = (bool) get_option( 'require_name_email', 1 ); |
| 87 | $fields = array( |
| 88 | 'author' => array( |
| 89 | 'label' => __( 'Name', 'woocommerce' ), |
| 90 | 'type' => 'text', |
| 91 | 'value' => $commenter['comment_author'], |
| 92 | 'required' => $name_email_required, |
| 93 | ), |
| 94 | 'email' => array( |
| 95 | 'label' => __( 'Email', 'woocommerce' ), |
| 96 | 'type' => 'email', |
| 97 | 'value' => $commenter['comment_author_email'], |
| 98 | 'required' => $name_email_required, |
| 99 | ), |
| 100 | ); |
| 101 | |
| 102 | $comment_form['fields'] = array(); |
| 103 | |
| 104 | foreach ( $fields as $key => $field ) { |
| 105 | $field_html = '<p class="comment-form-' . esc_attr( $key ) . '">'; |
| 106 | $field_html .= '<label for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] ); |
| 107 | |
| 108 | if ( $field['required'] ) { |
| 109 | $field_html .= ' <span class="required">*</span>'; |
| 110 | } |
| 111 | |
| 112 | $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>'; |
| 113 | |
| 114 | $comment_form['fields'][ $key ] = $field_html; |
| 115 | } |
| 116 | |
| 117 | $account_page_url = wc_get_page_permalink( 'myaccount' ); |
| 118 | if ( $account_page_url ) { |
| 119 | /* translators: %s opening and closing link tags respectively */ |
| 120 | $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>'; |
| 121 | } |
| 122 | |
| 123 | if ( wc_review_ratings_enabled() ) { |
| 124 | $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . ( wc_review_ratings_required() ? ' <span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required> |
| 125 | <option value="">' . esc_html__( 'Rate…', 'woocommerce' ) . '</option> |
| 126 | <option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option> |
| 127 | <option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option> |
| 128 | <option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option> |
| 129 | <option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option> |
| 130 | <option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option> |
| 131 | </select></div>'; |
| 132 | } |
| 133 | |
| 134 | $comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" required></textarea></p>'; |
| 135 | |
| 136 | comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) ); |
| 137 | ?> |
| 138 | </div> |
| 139 | </div> |
| 140 | <?php else : ?> |
| 141 | <p class="woocommerce-verification-required"><?php esc_html_e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p> |
| 142 | <?php endif; ?> |
| 143 | |
| 144 | <div class="clear"></div> |
| 145 | </div> |
| 146 |