【发布时间】:2020-08-27 15:41:50
【问题描述】:
我正在使用 WooCommerce 的 WYSIWYG 工具构建自定义产品页面。为了 CRO 的缘故,我想在页面底部添加评论。
我已经禁用了标签(评论、描述),我将在中间添加自定义内容,在底部添加评论。
我已经找到了一种显示评论的方法(来源:https://www.businessbloomer.com/woocommerce-display-product-reviews-custom-page-shortcode/)
add_shortcode( 'product_reviews', 'bbloomer_product_reviews_shortcode' );
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;
}
现在有问题 现在我想编辑简码,以便可以拉 /显示总平均产品评分(可能还有一个表格,但为此我可以喜欢不同的评论提交页面)。
【问题讨论】:
-
请在所见即所得工具中输入[product_reviews]。调用您的简码。请参考此网址wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress
-
抱歉,我不确定我是否理解您的解决方案。添加短代码将完成我已经在做的事情 - 通过其 ID 显示产品的评论。我想“复制”或接近它,woocommerce 使用简码审查功能。不仅意味着评级(正如 businessbloomer.com 的代码所做的那样),还意味着平均评级等。
-
你能分享你如何在所见即所得中使用这个短代码。你必须像这样传递产品 id [product_reviews id="your product id"]
-
是的,这就是我已经使用它的方式,这就是为什么我不明白你的解决方案。我已经以这种方式使用了简码
标签: php wordpress woocommerce e-commerce