Replies: 0
Hello,
I can’t seem to figure out how wc_update_product_lookup_tables_rating_count() function works.
I have a cron that inserts new comments/reviews on specific products, which looks something like this:
$commentdata = [
'comment_author' => $original_comment->comment_author,
'comment_author_email' => $original_comment->comment_author_email,
'comment_author_url' => $original_comment->comment_author_url,
'comment_author_IP' => $original_comment->comment_author_IP,
'comment_date' => $original_comment->comment_date,
'comment_date_gmt' => $original_comment->comment_date_gmt,
'comment_post_ID' => $post->ID,
'comment_content' => $original_comment->comment_content,
'comment_karma' => $original_comment->comment_karma,
'comment_approved' => 1,
'comment_agent' => $original_comment->comment_agent,
'comment_type' => $original_comment->comment_type,
'comment_parent' => $original_comment->comment_parent,
'user_id' => $original_comment->user_id,
'comment_meta' => [
'rating' => $comment_rating,
]
];
wp_insert_comment($commentdata);
So this is all the necessary data that wp_insert_comment requires for it to be inserted.
After this function executes, everything is fine, new review is inserted with correct data, but the wc_product_meta_lookup table needs to be updated.
I tried with this:
$test = [
[
'meta_value' => $comment_rating,
'post_id' => $post->ID
],
];
wc_update_product_lookup_tables_rating_count($test);
But this doesn’t work. I see that instead of average_rating, rating_count is being updated. I tried various examples with $test array but i can’t find the correct solution for this. Any help is appreciated.
- This topic was modified 1 hour, 31 minutes ago by kojaa.