/** * Get product review count for a product (not replies). Please note this is not cached. * * @since 2.7.0 * @param WC_Product $product * @return int */ public static function get_review_count_for_product(&$product) { global $wpdb; $count = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT COUNT(*) FROM {$wpdb->comments}\n\t\t\tWHERE comment_parent = 0\n\t\t\tAND comment_post_ID = %d\n\t\t\tAND comment_approved = '1'\n\t\t", $product->get_id())); $product->set_review_count($count); $data_store = $product->get_data_store(); $data_store->update_review_count($product); return $count; }