WooCommerce Create Product Review Programmatically

Our discussion today is focused on WooCommerce Create a Product Review Programmatically. In this discussion, we will talk about steps to create a review for a specific product. In business strategies, we need to add a review for a product. Therefore, to add a review, you need to have access to a product ID first.

Below is a complete illustration of the same:

  $data = array(
        'comment_post_ID' => 50, // product id you want to add review
        'comment_author' => 'Qaisar Satti', // author name
        'comment_author_email' => 'qaisarssatti@gmail.com', // author email
        'comment_author_url' => 'https://blog.qaisarsatti.com/',
        'comment_content' => 'Here is dummy review',
        'comment_type' => 'review', // add type review
        'comment_parent' => 0, // If you want to reply a comment then add parent review Id
        'user_id' => 0, // add user id if you want to attach it with user
        'comment_author_IP' => '',
        'comment_agent' => '',
        'comment_date' => '2021-11-11 12:00:00',
        'comment_approved' => 0, // use 1 for approved
     $comment_id = wp_insert_comment($data); // insert comment
update_comment_meta( $comment_id, 'rating', 5 );


Recent Blogs