I have a product vendor woocommerce setup on a wordpress site. People can sign up and add their own products, which are just custom post types, etc and other people who buy these products can review them. The reviews are part of WordPress' comment template for the custom post type Product. I'm using the following code to display single reviews (wordpress comments) from people who've bought the products(custom post types):
The main part that I wanted working was the star rating bit that's added through the woocommerce plugin:
echo('Rating: <div class="star-rating" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"><span style="width:' . ( get_comment_meta( $comment->comment_ID, 'rating', true ) / 5 ) * 100 . '%"><strong itemprop="ratingValue">' . get_comment_meta( $comment->comment_ID, 'rating', true ) . '</strong></span></div><br />');
The full code:
<?php
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$args = array(
'orderby' => 'date',
'post_type' => 'product',
'number' => '4',
'post_author' => $user_id
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo '<div>';
echo('Review By: ' . $comment->comment_author . '<br />');
echo('Product: ' . '<a href="' . post_permalink($comment->ID)
. '">' . $comment->post_title . '</a>' . '<br />');
echo('Date: ' . $comment->comment_date . '<br />');
echo('Rating: <div class="star-rating" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"><span style="width:' . ( get_comment_meta( $comment->comment_ID, 'rating', true ) / 5 ) * 100 . '%"><strong itemprop="ratingValue">' . get_comment_meta( $comment->comment_ID, 'rating', true ) . '</strong></span></div><br />');
echo('Review: ' . $comment->comment_content );
echo '</div>';
endforeach;
}
?>
This code was placed on a page and using the plugin Exec PHP it worked.
I added it to another page I created (regular wordpress page) and removed 'number' => 4, from the array so that ALL reviews (comments) would show. This didn't work. So I copied the code, character for character, and this still didn't work.
So it was displaying the rating, which is just comment meta, on their "admin" page but not on their "feedback" page.
Now I've loaded the website up and it's stopped displaying the ratings on either page.
Can anyone help shed some light on this?