From 67c5fd179484e045f1ab7421e643da1bba186049 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 15 Mar 2013 12:59:01 +0000 Subject: [PATCH] Fix reviews + use functions in reviews tab. --- readme.txt | 1 + templates/single-product-reviews.php | 25 +++++-------------------- woocommerce-functions.php | 1 + 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/readme.txt b/readme.txt index 312ac140a5b..49f546154ec 100644 --- a/readme.txt +++ b/readme.txt @@ -177,6 +177,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Fix - prettyPhoto next/prev links and thumbnail navigation no longer appear when there's only one attachment * Fix - Attribute base * Fix - Fixed adjust_price method in product class, allowing negative adjustments +* Fix - Ratings and rating count transient syncing. * Localization - Added indian rupees * Localization - Updated French translation by absoluteweb * Localization - Updated Brazilian translaction by Claudio Sanches diff --git a/templates/single-product-reviews.php b/templates/single-product-reviews.php index bd201e0b14f..1a0e00b791f 100644 --- a/templates/single-product-reviews.php +++ b/templates/single-product-reviews.php @@ -4,9 +4,9 @@ * * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 2.0.3 */ -global $woocommerce; +global $woocommerce, $product; if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -17,30 +17,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( get_option('woocommerce_enable_review_rating') == 'yes' ) { - $count = $wpdb->get_var( $wpdb->prepare(" - SELECT COUNT(meta_value) FROM $wpdb->commentmeta - LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID - WHERE meta_key = 'rating' - AND comment_post_ID = %d - AND comment_approved = '1' - AND meta_value > 0 - ", $post->ID ) ); - - $rating = $wpdb->get_var( $wpdb->prepare(" - SELECT SUM(meta_value) FROM $wpdb->commentmeta - LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID - WHERE meta_key = 'rating' - AND comment_post_ID = %d - AND comment_approved = '1' - ", $post->ID ) ); + $count = $product->get_rating_count(); if ( $count > 0 ) { - $average = number_format($rating / $count, 2); + $average = $product->get_average_rating(); echo '
'; - echo '
'.$average.' '.__( 'out of 5', 'woocommerce' ).'
'; + echo '
'.$average.' '.__( 'out of 5', 'woocommerce' ).'
'; echo '

'.sprintf( _n('%s review for %s', '%s reviews for %s', $count, 'woocommerce'), ''.$count.'', wptexturize($post->post_title) ).'

'; diff --git a/woocommerce-functions.php b/woocommerce-functions.php index 92f8b53b036..89885555a1c 100644 --- a/woocommerce-functions.php +++ b/woocommerce-functions.php @@ -1274,6 +1274,7 @@ function woocommerce_add_comment_rating($comment_id) { add_comment_meta( $comment_id, 'rating', (int) esc_attr( $_POST['rating'] ), true ); delete_transient( 'wc_average_rating_' . esc_attr($post->ID) ); + delete_transient( 'wc_rating_count_' . esc_attr($post->ID) ); } }