Skip to content

Instantly share code, notes, and snippets.

@jmabbas
Created December 30, 2025 12:21
Show Gist options
  • Select an option

  • Save jmabbas/b0c57659076fbf3686d983b2d349ba28 to your computer and use it in GitHub Desktop.

Select an option

Save jmabbas/b0c57659076fbf3686d983b2d349ba28 to your computer and use it in GitHub Desktop.
GoTrek - Reviews
<?php
/**
* Reviews for Single Hotel
*
* @package gotrek
*/
defined( 'ABSPATH' ) || exit;
global $product;
if ( ! comments_open() ) {
return;
}
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average = $product->get_average_rating();
?><div id="comments" class="gotrek-hotel-comments">
<?php
if ( have_comments() ) {
if ( get_option( 'woocommerce_review_rating_verification_required' ) !== 'no' ) {
/* translators: %s: verified guest review count. */
$reviews_title = sprintf( esc_html( _n( 'Showing %1$s verified guest review', 'Showing %1$s verified guest reviews', $rating_count, 'gotrek' ) ), esc_html( $rating_count ) );
} else {
/* translators: %s: review count. */
$reviews_title = sprintf( esc_html( _n( 'Showing %1$s review', 'Showing %1$s reviews', $rating_count, 'gotrek' ) ), esc_html( $rating_count ) );
}
} else {
$reviews_title = esc_html__( 'Reviews', 'gotrek' );
}
?>
<h4 class="comment-review-title"><?php echo esc_html( $reviews_title ); ?></h4>
<?php
if ( have_comments() ) :
?>
<ol class="commentlist list-unstyled">
<?php
/**
* Display the list of comments for WooCommerce product reviews.
*
* Retrieves and displays the comments for the current WooCommerce product using
* the specified arguments. This function outputs the list of comments structured
* according to the specified callback function.
*
* @since 4.3.0
*
* @param array $args {
* Optional. Array of arguments for displaying the comments list.
*
* @type string $callback Name of the callback function for displaying each comment.
* }
*/
wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) );
?>
</ol>
<?php
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
?>
<nav class="woocommerce-pagination">
<?php
/**
* Display pagination links for comments with WooCommerce settings.
*
* @since 1.0.0
*
* @param array $args {
* Arguments for comment pagination links.
*
* @type string 'prev_text' The previous page text. Default '&larr;' or '&rarr;' based on RTL.
* @type string 'next_text' The next page text. Default '&rarr;' or '&larr;' based on RTL.
* @type string 'type' The format of the returned value. Default 'list'.
* }
*/
paginate_comments_links(
apply_filters(
'woocommerce_comment_pagination_args',
array(
'prev_text' => is_rtl() ? '&rarr;' : '&larr;',
'next_text' => is_rtl() ? '&larr;' : '&rarr;',
'type' => 'list',
)
) // phpcs:ignore
);
?>
</nav>
<?php
endif;
else :
?>
<p class="woocommerce-noreviews alert alert-warning"><?php esc_html_e( 'There are no reviews yet.', 'gotrek' ); ?></p>
<?php
endif;
?>
</div><!-- /#comments -->
<?php
?>
<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>
<div id="review_form_wrapper" class="gotrek-review-wrapper">
<div id="review_form">
<?php
$commenter = wp_get_current_commenter();
$comment_form = array(
/* translators: %s is product title */
'title_reply' => have_comments() ? esc_html__( 'Add a review', 'gotrek' ) : sprintf( esc_html__( 'Be the first to review &ldquo;%s&rdquo;', 'gotrek' ), get_the_title() ),
/* translators: %s is product title */
'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'gotrek' ),
'title_reply_before' => '<h4 id="reply-title" class="comment-reply-title font-size-21 font-weight-bold text-dark mb-6">',
'title_reply_after' => '</h4>',
'comment_notes_after' => '',
'label_submit' => esc_html__( 'Submit', 'gotrek' ),
'class_submit' => 'btn rounded-xs bg-blue-dark-1 text-white p-2 height-51 width-190 transition-3d-hover submit',
'class_form' => 'row mb-5 mb-lg-0 comment-form',
'logged_in_as' => '',
'comment_field' => '',
'submit_field' => '<div class="form-submit col d-flex justify-content-center justify-content-lg-start">%1$s %2$s</div>',
);
$name_email_required = (bool) get_option( 'require_name_email', 1 );
$fields = array(
'author' => array(
'label' => esc_html__( 'Name', 'gotrek' ),
'type' => 'text',
'value' => $commenter['comment_author'],
'required' => $name_email_required,
),
'email' => array(
'label' => esc_html__( 'Email', 'gotrek' ),
'type' => 'email',
'value' => $commenter['comment_author_email'],
'required' => $name_email_required,
),
);
$comment_form['fields'] = array();
foreach ( $fields as $key => $field ) {
$field_html = '<div class="col-md-6 mb-5 comment-form-' . esc_attr( $key ) . '">';
$field_html .= '<label class="sr-only" for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] );
if ( $field['required'] ) {
$field_html .= '&nbsp;<span class="required">*</span>';
}
$field_html .= '</label><input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="' . esc_attr( $field['type'] ) . '" class="form-control" placeholder="' . esc_attr( $field['label'] ) . '" value="' . esc_attr( $field['value'] ) . '" size="30" ' . ( $field['required'] ? 'required' : '' ) . ' /></div>';
$comment_form['fields'][ $key ] = $field_html;
}
$account_page_url = wc_get_page_permalink( 'myaccount' );
if ( $account_page_url ) {
/* translators: %s opening and closing link tags respectively */
$comment_form['must_log_in'] = '<p class="col-12 must-log-in">' . sprintf( esc_html__( 'You must be %1$slogged in%2$s to post a review.', 'gotrek' ), '<a href="' . esc_url( $account_page_url ) . '">', '</a>' ) . '</p>';
}
if ( wc_review_ratings_enabled() ) {
$comment_form['comment_field'] = '<div class="col-12 mb-5 comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'gotrek' ) . ( wc_review_ratings_required() ? '&nbsp;<span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required>
<option value="">' . esc_html__( 'Rate&hellip;', 'gotrek' ) . '</option>
<option value="5">' . esc_html__( 'Perfect', 'gotrek' ) . '</option>
<option value="4">' . esc_html__( 'Good', 'gotrek' ) . '</option>
<option value="3">' . esc_html__( 'Average', 'gotrek' ) . '</option>
<option value="2">' . esc_html__( 'Not that bad', 'gotrek' ) . '</option>
<option value="1">' . esc_html__( 'Very poor', 'gotrek' ) . '</option>
</select></div>';
}
$comment_form['comment_field'] .= '<div class="col-sm-12 mb-5 comment-form-comment"><label class="sr-only" for="comment">' . esc_html__( 'Your review', 'gotrek' ) . '&nbsp;<span class="required">*</span></label><textarea class="form-control" id="comment" placeholder="' . esc_attr__( 'Your Review', 'gotrek' ) . '" name="comment" cols="45" rows="8" required></textarea></div>';
/**
* Filters the arguments used in the comment form for WooCommerce product reviews.
*
* @since 1.0.0
*
* @param array $comment_form The comment form arguments.
*/
comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
?>
</div>
</div>
<?php else : ?>
<p class="woocommerce-verification-required"><?php esc_html_e( 'Only logged in customers who have purchased this product may leave a review.', 'gotrek' ); ?></p>
<?php endif; ?>
</div><!-- #reviews -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment