From 1c7c6246e957ce806ff678276e7cec7a6c892957 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 12 Feb 2019 11:44:55 +0000 Subject: [PATCH] Comment rating functions should not update the object themselves --- includes/class-wc-comments.php | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/includes/class-wc-comments.php b/includes/class-wc-comments.php index ba1cc33afe2..76583cdbe42 100644 --- a/includes/class-wc-comments.php +++ b/includes/class-wc-comments.php @@ -195,12 +195,12 @@ class WC_Comments { * @param int $post_id Post ID. */ public static function clear_transients( $post_id ) { - if ( 'product' === get_post_type( $post_id ) ) { $product = wc_get_product( $post_id ); - self::get_rating_counts_for_product( $product ); - self::get_average_rating_for_product( $product ); - self::get_review_count_for_product( $product ); + $product->set_rating_count( self::get_rating_counts_for_product( $product ) ); + $product->set_average_rating( self::get_average_rating_for_product( $product ) ); + $product->set_review_count( self::get_review_count_for_product( $product ) ); + $product->save(); } } @@ -337,11 +337,6 @@ class WC_Comments { $average = 0; } - $product->set_average_rating( $average ); - - $data_store = $product->get_data_store(); - $data_store->update_average_rating( $product ); - return $average; } @@ -367,11 +362,6 @@ class WC_Comments { ) ); - $product->set_review_count( $count ); - - $data_store = $product->get_data_store(); - $data_store->update_review_count( $product ); - return $count; } @@ -405,11 +395,6 @@ class WC_Comments { $counts[ $count->meta_value ] = absint( $count->meta_value_count ); // WPCS: slow query ok. } - $product->set_rating_counts( $counts ); - - $data_store = $product->get_data_store(); - $data_store->update_rating_counts( $product ); - return $counts; }