/**
  * Get the reviews for a product
  *
  * @since 2.1
  * @param int $id the product ID to get reviews for
  * @param string $fields fields to include in response
  * @return array
  */
 public function get_product_reviews($id, $fields = null)
 {
     $id = $this->validate_request($id, 'product', 'read');
     if (is_wp_error($id)) {
         return $id;
     }
     $comments = get_approved_comments($id);
     $reviews = array();
     foreach ($comments as $comment) {
         $reviews[] = array('id' => intval($comment->comment_ID), 'created_at' => $this->server->format_datetime($comment->comment_date_gmt), 'review' => $comment->comment_content, 'rating' => get_comment_meta($comment->comment_ID, 'rating', true), 'reviewer_name' => $comment->comment_author, 'reviewer_email' => $comment->comment_author_email, 'verified' => wc_review_is_from_verified_owner($comment->comment_ID));
     }
     return array('product_reviews' => apply_filters('woocommerce_api_product_reviews_response', $reviews, $id, $fields, $comments, $this->server));
 }
 /**
  * Prepare a single product review output for response.
  *
  * @param WP_Comment $review Product review object.
  * @param WP_REST_Request $request Request object.
  * @return WP_REST_Response $response Response data.
  */
 public function prepare_item_for_response($review, $request)
 {
     $data = array('id' => (int) $review->comment_ID, 'date_created' => wc_rest_prepare_date_response($review->comment_date_gmt), 'review' => $review->comment_content, 'rating' => (int) get_comment_meta($review->comment_ID, 'rating', true), 'reviewer_name' => $review->comment_author, 'reviewer_email' => $review->comment_author_email, 'verified' => wc_review_is_from_verified_owner($review->comment_ID));
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     // Wrap the data in a response object.
     $response = rest_ensure_response($data);
     $response->add_links($this->prepare_links($review, $request));
     /**
      * Filter product reviews object returned from the REST API.
      *
      * @param WP_REST_Response $response The response object.
      * @param WP_Comment       $review   Product review object used to create response.
      * @param WP_REST_Request  $request  Request object.
      */
     return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request);
 }
Example #3
0
 * HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
 * will need to copy the new files to your theme to maintain compatibility. We try to do this.
 * as little as possible, but it does happen. When this occurs the version of the template file will.
 * be bumped and the readme will list any important changes.
 *
 * @see     http://docs.woothemes.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.5.0
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
$rating = intval(get_comment_meta($comment->comment_ID, 'rating', true));
$verified = wc_review_is_from_verified_owner($comment->comment_ID);
?>
<li itemprop="review" itemscope itemtype="http://schema.org/Review" <?php 
comment_class();
?>
 id="li-comment-<?php 
comment_ID();
?>
">

	<div id="comment-<?php 
comment_ID();
?>
" class="comment_container">

		<?php 
Example #4
0
        ?>
	
					<p class="meta"><em><?php 
        _e('Your comment is awaiting approval', 'swiftframework');
        ?>
</em></p>
	
				<?php 
    } else {
        ?>
	
					<p class="meta">
						<?php 
        if (get_option('woocommerce_review_rating_verification_label') === 'yes') {
            if (function_exists('wc_review_is_from_verified_owner')) {
                $verified = wc_review_is_from_verified_owner($comment_id);
                if ($verified) {
                    echo '<em class="verified">(' . __('verified owner', 'swiftframework') . ')</em> ';
                }
            }
        }
        ?>
					</p>
	
				<?php 
    }
    ?>
	
				<div itemprop="description" class="description">
	
					<?php