Hi @pear8398,
Following is the code that I am using to save a review programmatically and getting Anonymous in name every time. Is there any settings for this?
$rating_number = $_POST[‘rating_number’];
$product_id = $_POST[‘prod_id’];
$rev_name = $_POST[‘name’];
$rev_email = $_POST[’email’];
$rev_review = $_POST[‘content’];
$comment_id = wp_insert_comment( array(
'comment_post_ID' => $product_id, // <=== The product ID where the review will show up
'comment_author' => $rev_name,
'comment_author_email' => $rev_email, // <== Important
'comment_author_url' => '',
'comment_content' => $rev_review,
'comment_type' => 'review',
'comment_parent' => 0,
'user_id' => 0, // <== Important
'comment_author_IP' => '',
'comment_agent' => '',
'comment_date' => date('Y-m-d H:i:s'),
'comment_approved' => 0,
) );
// HERE inserting the rating (an integer from 1 to 5)
update_comment_meta( $comment_id, 'rating', $rating_number );
echo "Your Review has been submitted successfully!";