Skip to content

Instantly share code, notes, and snippets.

@gstricklind gstricklind/functions.php
Last active Mar 9, 2019

Embed
What would you like to do?
Product Reviews Shortcode - only works on single-product template
/*========================================================================
3 Column Reviews shortcode - can only be used on single product pages
https://ginastricklind.com/how-to-create-a-product-reviews-shortcode-query/
========================================================================*/
add_shortcode( 'display_latest_reviews', 'gs_display_latest_reviews' );
function gs_display_latest_reviews() {
if( is_product() ) {
global $product;
$id = $product->id;
$args = array (
'post_type' => 'product',
'post_id' => $id,
'orderby' => 'commment_date',
'order' => DESC,
'number' => '3',
);
$comments = get_comments( $args );
ob_start();
?>
<div id="gs-reviews">
<ul class="review-list">
<?php $list = wp_list_comments( array( 'callback' => 'woocommerce_comments' ), $comments); ?>
</ul>
</div>
<?
$output = ob_get_contents();
ob_get_clean();
return $output;
} else {
return 'shortcode must be used on a single product view';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.