从自定义模板添加woocommerce产品评论

时间:2018-11-20 13:45:19

标签: wordpress

我想从自定义模式弹出窗口中添加woo Commerce中产品的评论,所以有一种方法可以将这些评论添加到woo Commerce产品中。

2 个答案:

答案 0 :(得分:0)

查看@Maha Dev在this post上的最后一个条目...

示例:

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();

答案 1 :(得分:0)

您可以添加以下代码以将评论添加到您的woocommerce产品中

<?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);

如果您仍然遇到任何问题,请告诉我