If you are looking to save the values to the database for direct executing SQL, please follow this
WooCommerce keeps product reviews data as postmeta under meta keys
_wc_rating_count
_wc_average_rating
_wc_review_count
UPDATE fs_postmeta SET meta_value = 5
WHERE meta_key = '_wc_average_rating' AND post_id = 564;
UPDATE fs_postmeta SET meta_value = 105
WHERE meta_key = '_wc_review_count' AND post_id = 564;
Or
<?php
/*
Plugin Name: BK
Version: 0.0.1
*/
function bk_get_all_products( ) {
$ps = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '-1'
) );
$arr = array();
while($ps->have_posts()){
$ps->the_post();
$arr[] = get_the_ID();
}
return $arr;
}
add_action('init','bk');
function bk(){
$products = bk_get_all_products();
// $re = array(
// "1" => 1,
// "2" => 2,
// "3" => 3,
// "4" => 5,
// "5" => 6,
// );
foreach ($products as $key => $value) {
update_post_meta( $value, '_wc_average_rating', 1 );
update_post_meta( $value, '_wc_review_count', 15 );
// update_post_meta( $value, '_wc_rating_count', $re );
}
}