本文介绍了我想通过产品 ID 获得 woocommerce 评论并将其显示在模板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过产品 ID 或其他任何内容获取 woocommerce 产品评论,并希望将其显示在我创建的模板中.

I want to fetch woocommerce product reviews by product id or anything else and want to display it in a template created by me.

推荐答案

Woocommerce 根据常规的 wordpress 评论进行了评论.

Woocommerce made a reviews out of regular wordpress comments.

简单的方法是获取'post_type' => 'product'的评论,这将获得原始评论数据.为了显示正确的woocommerce评论,您需要应用一个回调函数女巫是'callback' => 'woocommerce_comments'.

The simple way is to get a comments of 'post_type' => 'product', that will get raw comment data. In order to display proper woocommerce review out of that you need to apply a callback function witch is 'callback' => 'woocommerce_comments'.

整件事是:

<?php
    $args = array ('post_type' => 'product');
    $comments = get_comments( $args );
    wp_list_comments( array( 'callback' => 'woocommerce_comments' ), $comments);
?>

如果您想通过产品 ID 获取评论,则需要更改 $args:

If you want to get the comment by product ID then you need to change that $args:

$args = array ('post_id' => 123);

要更多地自定义它,请查看引用:

To customize it more check out that references:

http://codex.wordpress.org/Function_Reference/wp_list_commentshttp://codex.wordpress.org/get_comments

'callback' => 'woocommerce_comments' 函数使用位于 plugins/woocomerce/templates/single-product/review.php 中的模板

The 'callback' => 'woocommerce_comments' function uses a template located in plugins/woocomerce/templates/single-product/review.php

这篇关于我想通过产品 ID 获得 woocommerce 评论并将其显示在模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:24