Programmatically – Create Comment with Star Rating – WP/ WooCommerce Review

Programmatically – Create Comment with Star Rating – WP/ WooCommerce Review

In this Tech Post We will see How we can Insert WordPress Comment with star rating or how to create Woocommerce Product reviews Programmatically.

Requirements for posting star rating or reviews in WordPress or WooCommerce product programmatically or with coding is below:

  • Post ID where you want to show rating or reviews
  • Review poster name and email address.
  • And then We will get Comment ID after inserting comment to that post.
  • with that comment ID we will add meta data to that comment ID that will store our star rating value.

Complete Code for Posting Star Rating to WordPress or Woocommrce

$data = array(
        'comment_post_ID' => 50, // product id you want to add review
        'comment_author' => 'ntAfzal', // author name
        'comment_author_email' => 'info@ntafzal.com', // author email
        'comment_author_url' => 'https://ntafzal.com/',
        'comment_content' => 'Here is testing review comment',
        '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 );

Related Posts

Add Your Comment


Comments

BGpFvXjbmfktHyAs
BGpFvXjbmfktHyAs | Posted on 14 May 2024

GJwyWipYrO

UHVkERIScGd
UHVkERIScGd | Posted on 24 April 2024

hFcviAIJg

UHVkERIScGd
UHVkERIScGd | Posted on 24 April 2024

hFcviAIJg

MutwlgPUWR
MutwlgPUWR | Posted on 21 April 2024

TmoxGHJue

MutwlgPUWR
MutwlgPUWR | Posted on 21 April 2024

TmoxGHJue

ceydorbpkfvQwMFx
ceydorbpkfvQwMFx | Posted on 06 April 2024

vkfLQuehRsaotIB

ceydorbpkfvQwMFx
ceydorbpkfvQwMFx | Posted on 06 April 2024

vkfLQuehRsaotIB

Winston
Winston | Posted on 24 March 2024

Winston here from Iowa. I'm always watching to see what newer sites are going up and I just wanted to see if you would like an extra hand with getting some targeted traffic, create videos/images/adcopy, remove negative listings, the list goes on. I'll even shoulder 90% of the costs, dedicating my time and tools that I've created myself and bought over the years. I've been doing this for over 22 years, helped thousands of people and have loved every minute of it. There's virtually no cost on my end to do any of this for you except for my time starting at 99 a month. I don't mean to impose; I was just curious if I could lend a hand. Brief history, I've been working from home for a couple decades now and I love helping others. I'm married, have three girls and if I can provide for them by helping you and giving back by using the tools and knowledge I've built and learned over the years, I can't think of a better win-win. It amazes me that no one else is helping others quite like I do and I'd love to show you how I can help out. So, if you need any extra help in any way, please let me know either way as I value your time and don't want to pester you. PS – If I didn’t mention something you might need help with just ask, I only mentioned a handful of things to keep this brief :-) All the best, Winston Cell - 1-319-435-1790‬ My Site (w/Live Chat) - https://cutt.ly/9wEWIZbQ

nYtLJPhXDx
nYtLJPhXDx | Posted on 22 March 2024

EYLGjADc

nYtLJPhXDx
nYtLJPhXDx | Posted on 22 March 2024

EYLGjADc

qibuXNsURnMoQcYw
qibuXNsURnMoQcYw | Posted on 14 March 2024

YlxSgCOZ

qibuXNsURnMoQcYw
qibuXNsURnMoQcYw | Posted on 14 March 2024

YlxSgCOZ

gDFUmwzixSGPbq
gDFUmwzixSGPbq | Posted on 07 February 2024

WBMeRAmkKZr

gDFUmwzixSGPbq
gDFUmwzixSGPbq | Posted on 07 February 2024

WBMeRAmkKZr

LDtBTjEP
LDtBTjEP | Posted on 30 January 2024

YHpEtreuZDxV