WooCommerce Create Post Comment Programmatically

Today’s discussion is aimed towards WooCommerce/Wordpress Create a Post Comment Programmatically. Here, we will discuss how to create a comment with a post. Oftentimes, we are faced with a need to add a comment to the posts. To add comments on any post, first of all, you need the post ID.

Below is an illustration for the same:

  $data = array(
        'comment_post_ID' => 50, // post id you want to add comment
        '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 comment',
        'comment_type' => 'comment', // add type of comment
        'comment_parent' => 0, // If you want to reply a comment then add parent comment 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
    );
     wp_insert_comment($data); // insert comment

Search

Recent Blogs

Categories

Archives

Archives

Tags