mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
33 lines
1.1 KiB
Text
33 lines
1.1 KiB
Text
add_shortcode( 'product_reviews', 'wc_product_reviews_shortcode' );
|
|
|
|
function wc_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;
|
|
}
|