Last active
August 27, 2022 09:13
-
-
Save FrancoStino/7c9e952a796c3963cb00d12e0f77d1ae to your computer and use it in GitHub Desktop.
WooCommerce Product Reviews Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// WooCommerce Product Reviews Shortcode | |
add_shortcode( 'product_reviews', 'bbloomer_product_reviews_shortcode' ); | |
function bbloomer_product_reviews_shortcode() { | |
$args = array( | |
'status' => 'approve', | |
'type' => 'review', | |
); | |
// The Query | |
$comments = get_comments($args); | |
$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 .= '<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 .= '<div style="padding-top:20px" class="woodmart-button-wrapper text-left"><a href="'.get_comment_link($comment->comment_ID).'" title="Visualizza la recensione" class="btn btn-color-primary btn-style-default btn-style-semi-round btn-size-medium" target="_blank">Vedi la recensione</a></div>'; | |
$html .= '</li>'; | |
} | |
$html .= '</ol></div></div>'; | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment