Comment rating functions should not update the object themselves

This commit is contained in:
Mike Jolley 2019-02-12 11:44:55 +00:00
parent 25117aa77b
commit 1c7c6246e9
1 changed files with 4 additions and 19 deletions

View File

@ -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;
}