Merge pull request #6850 from bryceadams/patch-6839
improve get_rating_count() for rating-less reviews
This commit is contained in:
commit
2c6debf1f4
|
@ -994,6 +994,8 @@ class WC_Product {
|
||||||
|
|
||||||
$where_meta_value = $value ? $wpdb->prepare( " AND meta_value = %d", $value ) : " AND meta_value > 0";
|
$where_meta_value = $value ? $wpdb->prepare( " AND meta_value = %d", $value ) : " AND meta_value > 0";
|
||||||
|
|
||||||
|
if ( get_option( 'woocommerce_enable_review_rating' ) == 'yes' && get_option( 'woocommerce_review_rating_required' ) == 'yes' ) {
|
||||||
|
|
||||||
$count = $wpdb->get_var( $wpdb->prepare("
|
$count = $wpdb->get_var( $wpdb->prepare("
|
||||||
SELECT COUNT(meta_value) FROM $wpdb->commentmeta
|
SELECT COUNT(meta_value) FROM $wpdb->commentmeta
|
||||||
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
|
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
|
||||||
|
@ -1002,6 +1004,17 @@ class WC_Product {
|
||||||
AND comment_approved = '1'
|
AND comment_approved = '1'
|
||||||
", $this->id ) . $where_meta_value );
|
", $this->id ) . $where_meta_value );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$count = $wpdb->get_var( $wpdb->prepare("
|
||||||
|
SELECT COUNT(*) FROM $wpdb->comments
|
||||||
|
WHERE comment_parent = 0
|
||||||
|
AND comment_post_ID = %d
|
||||||
|
AND comment_approved = '1'
|
||||||
|
", $this->id ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
set_transient( 'wc_rating_count_' . $this->id . $value_suffix, $count, YEAR_IN_SECONDS );
|
set_transient( 'wc_rating_count_' . $this->id . $value_suffix, $count, YEAR_IN_SECONDS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue