【发布时间】:2021-05-06 09:11:57
【问题描述】:
您好,我在 woocommerce 上启用了评论,但未显示在产品页面上,我将此代码放在 sn-ps 中
function bbloomer_product_reviews_shortcode( $atts ) {
if ( empty( $atts ) ) return '';
if ( ! isset( $atts['id'] ) ) return '';
$comments = get_comments( 'post_id=' . $atts['id'] );
if ( ! $comments ) return '';
$html .= '<div class="woocommerce-tabs"><div id="reviews"><ol class="commentlist">';
foreach ( $comments as $comment ) {
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
$html .= '<li class="review">';
$html .= get_avatar( $comment, '60' );
$html .= '<div class="comment-text">';
if ( $rating ) $html .= wc_get_rating_html( $rating );
$html .= '<p class="meta"><strong class="woocommerce-review__author">';
$html .= get_comment_author( $comment );
$html .= '</strong></p>';
$html .= '<div class="description">';
$html .= $comment->comment_content;
$html .= '</div></div>';
$html .= '</li>';
}
$html .= '</ol></div></div>';
return $html;
}
add_shortcode( 'woocommerce_after_single_product', 'bbloomer_product_reviews_shortcode' );
我在讨论中检查了所有产品和 woocommerce 中的启用评论
【问题讨论】:
-
你把这个
woocommerce_after_single_product短代码放在哪里了? -
在functions.php中
-
你把
[woocommerce_after_single_product]放在哪里了? -
这是我使用的简码 [product_reviews id="id for product"] 而不是 [woocommerce_after_single_product]。我把它放在产品描述中
-
你应该输入这个
[woocommerce_after_single_product]而不是[product_reviews ]短代码
标签: wordpress woocommerce