@Nikola\'sanswer 提供所需内容,而无需将任何内容保存到数据库中。如果you 需要将值保存到数据库并直接执行SQL,可以执行以下操作。
基本上,WooCommerce将产品评论数据存储为meta keys
wc\\U评级\\U计数
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;
或
<?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 );
}
}
记住,我们不会更改产品选项卡下显示的评论列表。