1

I want to add the reviews of the product in woo commerce from a custom modal popup so is there a way that I can add those review into the woo commerce product.

pkbhatt
  • 26
  • 4
  • Possible duplicate of [Add a product review with ratings programmatically in Woocommerce](https://stackoverflow.com/questions/52122275/add-a-product-review-with-ratings-programmatically-in-woocommerce) – Jamie_D Nov 20 '18 at 14:51
  • No it is not duplicated as I need to get the data from the custom form However I will try if I can get something from the above link @Jamie_D – pkbhatt Nov 21 '18 at 07:42

2 Answers2

0

See the last entry by @Maha Dev on this post ...

Example:

global $product;
$p_id = $product->get_id();

$comment_and_reviews = $wpdb->get_results("SELECT wpc.comment_author,wpc.comment_author_email,wpc.comment_date,wpc.comment_content,wpcm.meta_value AS rating FROM `" . $wpdb->prefix . "comments` AS wpc INNER JOIN  `" . $wpdb->prefix . "commentmeta` AS wpcm ON wpcm.comment_id = wpc.comment_id AND wpcm.meta_key = 'rating' WHERE wpc.comment_post_id = '" . $p_id . "' ");
print_r($comment_and_reviews);
exit();
Jamie_D
  • 979
  • 6
  • 13
  • This helps in displaying I need to add this from frontend – pkbhatt Nov 21 '18 at 10:13
  • You can use this code in a template or a template part. If your modal is not either, your need to load WordPress in your modal: `require('/path/to/wp-load.php');` I do suggest making your modal a [template part](https://developer.wordpress.org/reference/functions/get_template_part/) – Jamie_D Nov 21 '18 at 10:24
0

You may please add the following code to add review into your woocommerce product

<?php
require('../../../../wp-config.php');
global $wpdb;   
$data = array(
    'comment_post_ID' => 1,
    'comment_author' => 'admin',
    'comment_author_email' =>'admin@example.com',
    'comment_author_url' => 'http://example.com',
    'comment_content' => 'My review',
    'comment_type' => '',
    'comment_parent' => 0,
    'user_id' => 1,
    'comment_approved' => 1,
);

wp_insert_comment($data);

Do let me know if you still face any issue into this

Pratik bhatt
  • 488
  • 8
  • 23