WC_Structured_Data::generate_review_data( WP_Comment $comment )
Generates Review structured data.
Description Description
Hooked into woocommerce_review_meta
action hook.
Parameters Parameters
- $comment
-
(Required) Comment data.
Source Source
File: includes/class-wc-structured-data.php
public function generate_review_data( $comment ) { $markup = array(); $markup['@type'] = 'Review'; $markup['@id'] = get_comment_link( $comment->comment_ID ); $markup['datePublished'] = get_comment_date( 'c', $comment->comment_ID ); $markup['description'] = get_comment_text( $comment->comment_ID ); $markup['itemReviewed'] = array( '@type' => 'Product', 'name' => get_the_title( $comment->comment_post_ID ), ); // Skip replies unless they have a rating. $rating = get_comment_meta( $comment->comment_ID, 'rating', true ); if ( $rating ) { $markup['reviewRating'] = array( '@type' => 'Rating', 'bestRating' => '5', 'ratingValue' => $rating, 'worstRating' => '1', ); } elseif ( $comment->comment_parent ) { return; } $markup['author'] = array( '@type' => 'Person', 'name' => get_comment_author( $comment->comment_ID ), ); $this->set_data( apply_filters( 'woocommerce_structured_data_review', $markup, $comment ) ); }