Modify or Write a code to create a woocommerce reviews sort and feedback (Like/Dislike)…
- User
Modify or Write a code to create a woocommerce reviews sort and feedback (Like/Dislike) features and modify the reviews pagination with Ajax
There should be two options to sort the reviews: first Sort by, second Filter by rating.
- Sort By: Option like - Latest, Oldest, Highest Raring, Lowest Rating.
- Filter by Rating: Option like - 5 Star, 4 Star, 3 Star, 2 Star, 1 Star.
- Replace WooCommerce review pagination with AJAX to make it work without reloading the webpage.
- add reviews feedback (Like/Dislike) features.
<?php if ( have_comments() ) : ?> <ol class="commentlist"> <?php 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' ) ) : echo '<nav class="woocommerce-pagination">'; paginate_comments_links( apply_filters( 'woocommerce_comment_pagination_args', array( 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'type' => 'list', ) ) ); echo '</nav>'; endif; ?> <?php else : ?> <p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p> <?php endif; ?> </div> <?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"> <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', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review “%s”', 'woocommerce' ), get_the_title() ), /* translators: %s is product title */ 'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'woocommerce' ), 'title_reply_before' => '<span id="reply-title" class="comment-reply-title" role="heading" aria-level="3">', 'title_reply_after' => '</span>', 'comment_notes_after' => '', 'label_submit' => esc_html__( 'Submit', 'woocommerce' ), 'logged_in_as' => '', 'comment_field' => '', ); $name_email_required = (bool) get_option( 'require_name_email', 1 ); $fields = array( 'author' => array( 'label' => __( 'Name', 'woocommerce' ), 'type' => 'text', 'value' => $commenter['comment_author'], 'required' => $name_email_required, 'autocomplete' => 'name', ), 'email' => array( 'label' => __( 'Email', 'woocommerce' ), 'type' => 'email', 'value' => $commenter['comment_author_email'], 'required' => $name_email_required, 'autocomplete' => 'email', ), ); $comment_form['fields'] = array(); foreach ( $fields as $key => $field ) { $field_html = '<p class="comment-form-' . esc_attr( $key ) . '">'; $field_html .= '<label for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] ); if ( $field['required'] ) { $field_html .= ' <span class="required">*</span>'; } $field_html .= '</label><input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="' . esc_attr( $field['type'] ) . '" autocomplete="' . esc_attr( $field['autocomplete'] ) . '" value="' . esc_attr( $field['value'] ) . '" size="30" ' . ( $field['required'] ? 'required' : '' ) . ' /></p>'; $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="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>'; } if ( wc_review_ratings_enabled() ) { $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating" id="comment-form-rating-label">' . esc_html__( 'Your rating', 'woocommerce' ) . ( wc_review_ratings_required() ? ' <span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required> <option value="">' . esc_html__( 'Rate…', 'woocommerce' ) . '</option> <option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option> <option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option> <option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option> <option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option> <option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option> </select></div>'; } $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>'; 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.', 'woocommerce' ); ?></p> <?php endif; ?> <div class="clear"></div> Assistant
Of course! This is a comprehensive request that involves modifying a WooCommerce template, adding custom PHP functions for AJAX handling and data storage, and writing JavaScript to tie it all together.
Here is a complete, step-by-step solution.
Instructions
-
Create a Child Theme: It's crucial to use a child theme for these modifications. If you edit your main theme files, your changes will be lost when the theme is updated.
-
File 1:
single-product-reviews.php- Create a folder named
woocommerceinside your child theme's directory. - Inside that
woocommercefolder, create a new file namedsingle-product-reviews.php. - Copy and paste the code from Part 1 below into this new file.
- Create a folder named
-
File 2:
functions.php- Open the
functions.phpfile from your child theme's directory. - Copy and paste the code from Part 2 at the end of this file.
- Open the
-
File 3:
custom-reviews.js- In your child theme's directory, create a new folder named
js. - Inside this
jsfolder, create a new file namedcustom-reviews.js. - Copy and paste the code from Part 3 into this new file.
- In your child theme's directory, create a new folder named
-
File 4: Add CSS
- Open your child theme's
style.cssfile. - Copy and paste the CSS code from Part 4 at the end of the file to style the new features.
- Open your child theme's
Part 1: Modified Template (
your-child-theme/woocommerce/single-product-reviews.php)This code adds the sorting/filtering form and a container div (
#reviews-container) that our AJAX will target. It also adds adata-product-idattribute for our JavaScript to easily access.<?php /** * Display single product reviews (comments) - MODIFIED FOR AJAX SORT/FILTER/PAGINATION & FEEDBACK * * This template can be overridden by copying it to yourtheme/woocommerce/single-product-reviews.php. */ defined( 'ABSPATH' ) || exit; global $product; if ( ! comments_open() ) { return; } ?> <div id="reviews" class="woocommerce-Reviews" data-product-id="<?php echo esc_attr( $product->get_id() ); ?>"> <div id="comments"> <h2 class="woocommerce-Reviews-title"> <?php $count = $product->get_review_count(); if ( $count && wc_review_ratings_enabled() ) { /* translators: 1: reviews count 2: product name */ $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>' ); echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $product ); // WPCS: XSS ok. } else { esc_html_e( 'Reviews', 'woocommerce' ); } ?> </h2> <?php if ( have_comments() ) : ?> <div class="reviews-filter-form-wrapper"> <form id="reviews-filter-form" class="reviews-filter-form"> <div class="filter-group sort-by"> <label for="sort-by"><?php esc_html_e( 'Sort by:', 'woocommerce' ); ?></label> <select name="sort-by" id="sort-by"> <option value="latest"><?php esc_html_e( 'Most Recent', 'woocommerce' ); ?></option> <option value="oldest"><?php esc_html_e( 'Oldest', 'woocommerce' ); ?></option> <option value="highest_rating"><?php esc_html_e( 'Highest Rating', 'woocommerce' ); ?></option> <option value="lowest_rating"><?php esc_html_e( 'Lowest Rating', 'woocommerce' ); ?></option> </select> </div> <div class="filter-group filter-by-rating"> <label for="filter-rating"><?php esc_html_e( 'Filter by:', 'woocommerce' ); ?></label> <select name="filter-rating" id="filter-rating"> <option value=""><?php esc_html_e( 'All Ratings', 'woocommerce' ); ?></option> <option value="5"><?php esc_html_e( '5 Star', 'woocommerce' ); ?></option> <option value="4"><?php esc_html_e( '4 Star', 'woocommerce' ); ?></option> <option value="3"><?php esc_html_e( '3 Star', 'woocommerce' ); ?></option> <option value="2"><?php esc_html_e( '2 Star', 'woocommerce' ); ?></option> <option value="1"><?php esc_html_e( '1 Star', 'woocommerce' ); ?></option> </select> </div> </form> </div> <div id="reviews-container"> <ol class="commentlist"> <?php 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' ) ) : echo '<nav class="woocommerce-pagination">'; paginate_comments_links( apply_filters( 'woocommerce_comment_pagination_args', array( 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'type' => 'list', ) ) ); echo '</nav>'; endif; ?> </div> <?php else : ?> <p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p> <?php endif; ?> </div> <?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"> <div id="review_form"> <?php $commenter = wp_get_current_commenter(); $comment_form = array( 'title_reply' => have_comments() ? esc_html__( 'Add a review', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review “%s”', 'woocommerce' ), get_the_title() ), 'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'woocommerce' ), 'title_reply_before' => '<span id="reply-title" class="comment-reply-title" role="heading" aria-level="3">', 'title_reply_after' => '</span>', 'comment_notes_after' => '', 'label_submit' => esc_html__( 'Submit', 'woocommerce' ), 'logged_in_as' => '', 'comment_field' => '', ); $name_email_required = (bool) get_option( 'require_name_email', 1 ); $fields = array( 'author' => array( 'label' => __( 'Name', 'woocommerce' ), 'type' => 'text', 'value' => $commenter['comment_author'], 'required' => $name_email_required, ), 'email' => array( 'label' => __( 'Email', 'woocommerce' ), 'type' => 'email', 'value' => $commenter['comment_author_email'], 'required' => $name_email_required, ), ); $comment_form['fields'] = array(); foreach ( $fields as $key => $field ) { $field_html = '<p class="comment-form-' . esc_attr( $key ) . '">'; $field_html .= '<label for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] ); if ( $field['required'] ) { $field_html .= ' <span class="required">*</span>'; } $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>'; $comment_form['fields'][ $key ] = $field_html; } $account_page_url = wc_get_page_permalink( 'myaccount' ); if ( $account_page_url ) { $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>'; } if ( wc_review_ratings_enabled() ) { $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating" id="comment-form-rating-label">' . esc_html__( 'Your rating', 'woocommerce' ) . ( wc_review_ratings_required() ? ' <span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required> <option value="">' . esc_html__( 'Rate…', 'woocommerce' ) . '</option> <option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option> <option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option> <option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option> <option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option> <option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option> </select></div>'; } $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>'; 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.', 'woocommerce' ); ?></p> <?php endif; ?> <div class="clear"></div> </div>
Part 2: PHP Functions (
your-child-theme/functions.php)This code handles all the backend logic: enqueuing scripts, creating AJAX endpoints to fetch sorted/filtered reviews, and handling the like/dislike feedback.
<?php /** * Enqueue scripts and styles for custom review functionality. */ function custom_reviews_enqueue_scripts() { // Only load on single product pages if ( is_product() ) { // Enqueue our custom JS file wp_enqueue_script( 'custom-reviews-js', get_stylesheet_directory_uri() . '/js/custom-reviews.js', array( 'jquery' ), '1.0.0', true // Load in footer ); // Pass data to our script wp_localize_script( 'custom-reviews-js', 'custom_reviews_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'custom-reviews-nonce' ), ) ); } } add_action( 'wp_enqueue_scripts', 'custom_reviews_enqueue_scripts' ); /** * AJAX handler for loading product reviews with sorting and filtering. */ function custom_load_product_reviews() { check_ajax_referer( 'custom-reviews-nonce', 'nonce' ); $product_id = isset( $_POST['product_id'] ) ? intval( $_POST['product_id'] ) : 0; $paged = isset( $_POST['paged'] ) ? intval( $_POST['paged'] ) : 1; $sort_by = isset( $_POST['sort_by'] ) ? sanitize_key( $_POST['sort_by'] ) : 'latest'; $filter_rating = isset( $_POST['filter_rating'] ) ? intval( $_POST['filter_rating'] ) : 0; if ( ! $product_id ) { wp_send_json_error( 'Invalid Product ID' ); } // Base query arguments for get_comments $args = array( 'post_id' => $product_id, 'status' => 'approve', 'type' => 'review', 'paged' => $paged, 'number' => get_option( 'comments_per_page' ), ); // Handle sorting switch ( $sort_by ) { case 'oldest': $args['orderby'] = 'comment_date_gmt'; $args['order'] = 'ASC'; break; case 'highest_rating': $args['meta_key'] = 'rating'; $args['orderby'] = 'meta_value_num'; $args['order'] = 'DESC'; break; case 'lowest_rating': $args['meta_key'] = 'rating'; $args['orderby'] = 'meta_value_num'; $args['order'] = 'ASC'; break; case 'latest': default: $args['orderby'] = 'comment_date_gmt'; $args['order'] = 'DESC'; break; } // Handle rating filter if ( $filter_rating > 0 && $filter_rating <= 5 ) { $args['meta_query'][] = array( 'key' => 'rating', 'value' => $filter_rating, 'compare' => '=', 'type' => 'numeric', ); } // Get total comments for pagination calculation $all_comments_query = new WP_Comment_Query; $all_comments = $all_comments_query->query($args); $total_comments = count($all_comments); // Get paged comments $comments = get_comments( $args ); ob_start(); if ( $comments ) { echo '<ol class="commentlist">'; wp_list_comments( array( 'callback' => 'woocommerce_comments', 'per_page' => get_option( 'comments_per_page' ) ), $comments ); echo '</ol>'; // Manually create pagination $total_pages = ceil( $total_comments / get_option( 'comments_per_page' ) ); if ( $total_pages > 1 ) { echo '<nav class="woocommerce-pagination">'; echo paginate_links( array( 'base' => '#', // We handle navigation with JS 'format' => '', 'current' => $paged, 'total' => $total_pages, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'type' => 'list', ) ); echo '</nav>'; } } else { echo '<p class="woocommerce-noreviews">' . esc_html__( 'No reviews found with the selected filters.', 'woocommerce' ) . '</p>'; } $html = ob_get_clean(); wp_send_json_success( array( 'html' => $html ) ); } add_action( 'wp_ajax_load_product_reviews', 'custom_load_product_reviews' ); add_action( 'wp_ajax_nopriv_load_product_reviews', 'custom_load_product_reviews' ); /** * Add review feedback buttons (Like/Dislike) after the comment text. */ function display_review_feedback_buttons( $comment ) { if ( ! is_user_logged_in() ) { return; // Optional: Only show for logged-in users } $comment_id = $comment->comment_ID; $likes = get_comment_meta( $comment_id, '_review_likes', true ) ?: 0; $dislikes = get_comment_meta( $comment_id, '_review_dislikes', true ) ?: 0; // Check if current user has already voted $user_id = get_current_user_id(); $user_vote = get_comment_meta( $comment_id, '_user_vote_' . $user_id, true ); $like_class = ( $user_vote === 'like' ) ? 'active' : ''; $dislike_class = ( $user_vote === 'dislike' ) ? 'active' : ''; echo '<div class="review-feedback" data-comment-id="' . esc_attr( $comment_id ) . '">'; echo '<button class="review-feedback-button like ' . esc_attr($like_class) . '" data-action="like">👍 <span class="feedback-count">' . esc_html( $likes ) . '</span></button>'; echo '<button class="review-feedback-button dislike ' . esc_attr($dislike_class) . '" data-action="dislike">👎 <span class="feedback-count">' . esc_html( $dislikes ) . '</span></button>'; echo '</div>'; } // Use a hook that fires within the woocommerce_comments callback add_action( 'woocommerce_review_after_comment_text', 'display_review_feedback_buttons', 10, 1 ); /** * AJAX handler for review feedback (Like/Dislike). */ function handle_review_feedback() { check_ajax_referer( 'custom-reviews-nonce', 'nonce' ); if ( ! is_user_logged_in() ) { wp_send_json_error( array( 'message' => 'You must be logged in to vote.' ) ); } $comment_id = isset( $_POST['comment_id'] ) ? intval( $_POST['comment_id'] ) : 0; $action = isset( $_POST['feedback_action'] ) ? sanitize_key( $_POST['feedback_action'] ) : ''; $user_id = get_current_user_id(); if ( ! $comment_id || ! in_array( $action, ['like', 'dislike'] ) ) { wp_send_json_error( array( 'message' => 'Invalid data.' ) ); } $likes = get_comment_meta( $comment_id, '_review_likes', true ) ?: 0; $dislikes = get_comment_meta( $comment_id, '_review_dislikes', true ) ?: 0; $user_vote = get_comment_meta( $comment_id, '_user_vote_' . $user_id, true ); if ( $user_vote === $action ) { // User is un-voting if ( $action === 'like' ) $likes--; if ( $action === 'dislike' ) $dislikes--; delete_comment_meta( $comment_id, '_user_vote_' . $user_id ); } else { // New vote or changing vote if ( $user_vote === 'like' ) $likes--; if ( $user_vote === 'dislike' ) $dislikes--; if ( $action === 'like' ) $likes++; if ( $action === 'dislike' ) $dislikes++; update_comment_meta( $comment_id, '_user_vote_' . $user_id, $action ); } update_comment_meta( $comment_id, '_review_likes', $likes ); update_comment_meta( $comment_id, '_review_dislikes', $dislikes ); wp_send_json_success( array( 'likes' => $likes, 'dislikes' => $dislikes ) ); } add_action( 'wp_ajax_handle_review_feedback', 'handle_review_feedback' );
Part 3: JavaScript (
your-child-theme/js/custom-reviews.js)This script handles all the frontend interactions: detecting changes, making AJAX calls, and updating the review list and feedback counts.
jQuery(document).ready(function ($) { 'use strict'; // A function to fetch reviews via AJAX function fetchReviews(page) { var product_id = $('#reviews').data('product-id'); var sort_by = $('#sort-by').val(); var filter_rating = $('#filter-rating').val(); var paged = page || 1; // Default to page 1 if not provided // Show a loading indicator $('#reviews-container').addClass('loading'); $.ajax({ url: custom_reviews_ajax.ajax_url, type: 'POST', data: { action: 'load_product_reviews', nonce: custom_reviews_ajax.nonce, product_id: product_id, paged: paged, sort_by: sort_by, filter_rating: filter_rating }, success: function (response) { if (response.success) { $('#reviews-container').html(response.data.html); } else { // Optional: handle error console.error('Failed to load reviews.'); } }, error: function () { console.error('AJAX request failed.'); }, complete: function () { // Remove loading indicator $('#reviews-container').removeClass('loading'); } }); } // Event handler for filter/sort dropdowns $('#reviews-filter-form').on('change', 'select', function (e) { e.preventDefault(); fetchReviews(1); // Fetch the first page when filters change }); // Event handler for AJAX pagination // Use a delegated event handler since the pagination is replaced by AJAX $('#reviews').on('click', '.woocommerce-pagination a.page-numbers', function (e) { e.preventDefault(); // Extract page number from the link's href var pageUrl = $(this).attr('href'); var pageNum; // This regex finds the page number from the query string, e.g., ?cpage=2 var pageMatch = pageUrl.match(/cpage=(\d+)/); if (pageMatch) { pageNum = parseInt(pageMatch[1], 10); } else if ($(this).hasClass('next')) { pageNum = parseInt($('.woocommerce-pagination .current').text(), 10) + 1; } else if ($(this).hasClass('prev')) { pageNum = parseInt($('.woocommerce-pagination .current').text(), 10) - 1; } else { pageNum = parseInt($(this).text(), 10); } if (!isNaN(pageNum)) { fetchReviews(pageNum); } }); // Event handler for review feedback (Like/Dislike) $('#reviews').on('click', '.review-feedback-button', function(e) { e.preventDefault(); var $button = $(this); var $container = $button.closest('.review-feedback'); var comment_id = $container.data('comment-id'); var feedback_action = $button.data('action'); if ($button.hasClass('processing')) { return; // Prevent multiple clicks } $button.addClass('processing'); $.ajax({ url: custom_reviews_ajax.ajax_url, type: 'POST', data: { action: 'handle_review_feedback', nonce: custom_reviews_ajax.nonce, comment_id: comment_id, feedback_action: feedback_action }, success: function(response) { if (response.success) { // Update counts $container.find('.like .feedback-count').text(response.data.likes); $container.find('.dislike .feedback-count').text(response.data.dislikes); // Update active state $container.find('.review-feedback-button').removeClass('active'); if ($button.hasClass(feedback_action) && response.data.user_vote === feedback_action) { $button.addClass('active'); } } else { alert(response.data.message || 'An error occurred.'); } }, error: function() { alert('Request failed. Please try again.'); }, complete: function() { $button.removeClass('processing'); } }); }); });
Part 4: CSS (
your-child-theme/style.css)This CSS adds some basic styling for the new elements to make them look clean and functional.
/* --- Custom WooCommerce Review Styles --- */ /* Filter Form Styling */ .reviews-filter-form-wrapper { margin-bottom: 2em; padding-bottom: 1em; border-bottom: 1px solid #e0e0e0; } .reviews-filter-form { display: flex; gap: 1.5em; align-items: center; flex-wrap: wrap; } .reviews-filter-form .filter-group { display: flex; align-items: center; gap: 0.5em; } .reviews-filter-form label { font-weight: bold; margin-bottom: 0; } .reviews-filter-form select { min-width: 150px; } /* AJAX Loading Indicator */ #reviews-container { position: relative; transition: opacity 0.3s ease-in-out; } #reviews-container.loading { opacity: 0.5; pointer-events: none; /* Prevent clicks while loading */ } #reviews-container.loading::before { content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; /* Blue spinner */ border-radius: 50%; animation: spin 1s linear infinite; z-index: 10; } @keyframes spin { 0% { transform: translate(-50%, -50%) rotate(0deg); } 100% { transform: translate(-50%, -50%) rotate(360deg); } } /* Review Feedback (Like/Dislike) Buttons */ .review-feedback { margin-top: 1em; display: flex; align-items: center; gap: 0.5em; } .review-feedback-button { background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; padding: 5px 10px; cursor: pointer; font-size: 14px; transition: background-color 0.2s, border-color 0.2s; line-height: 1; } .review-feedback-button:hover { background-color: #e0e0e0; border-color: #bbb; } .review-feedback-button.active { background-color: #0073aa; /* WordPress blue */ color: #fff; border-color: #0073aa; } .review-feedback-button .feedback-count { margin-left: 0.3em; } .review-feedback-button.processing { opacity: 0.7; cursor: not-allowed; } /* Ensure AJAX pagination links look right */ .woocommerce-pagination ul { margin: 0; padding: 0; }After adding all these files and code, clear any caching plugins you might be using and test the single product page. You should now see the sorting dropdowns, and both they and the pagination should work instantly without a page reload. You'll also see like/dislike buttons on each review (for logged-in users).
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.