WC_API_Products::get_product_reviews()
Get the reviews for a product
Метод класса: WC_API_Products{}
Хуки из метода
Возвращает
Массив|WP_Error
.
Использование
$WC_API_Products = new WC_API_Products(); $WC_API_Products->get_product_reviews( $id, $fields );
- $id(int) (обязательный)
- the product ID to get reviews for
- $fields(строка)
- fields to include in response
По умолчанию: null
Список изменений
С версии 2.1 | Введена. |
Код WC_API_Products::get_product_reviews() WC API Products::get product reviews WC 7.5.1
public function get_product_reviews( $id, $fields = null ) { $id = $this->validate_request( $id, 'product', 'read' ); if ( is_wp_error( $id ) ) { return $id; } $args = array( 'post_id' => $id, 'approve' => 'approve', ); $comments = get_comments( $args ); $reviews = array(); foreach ( $comments as $comment ) { $reviews[] = array( 'id' => $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 ) ); }