我想通过产品id或其他任何东西来获取woocommerce产品评论,并希望将其显示在我创建的模板中。
发布于 2021-09-26 07:24:00
我花了一周的时间找到并找到了一种简单的方法。
如果想要将评论产品带到页面,只需使用WP_Query并将echo comments_template()放入其中
或者,如果您想要自定义模板检查,可以使用wp-content/plugins/woocommerce/templates/single-product-reviews.php中的模板并放入WP_Query中
在我的示例中,我希望将产品id为33051的评论带到主页
<?php
$args = array('post_type' => 'product','id' => 33051);
$result = new WP_Query( $args );
if ( $result-> have_posts() ) : ?>
<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<?php comments_template(); // you can custom template by code in single-product-reviews.php
?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>https://stackoverflow.com/questions/19372368
复制相似问题