WC_Structured_Data::generate_review_data
Generates Review structured data.
Hooked into woocommerce_review_meta hook.
Method of the class: WC_Structured_Data{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Structured_Data = new WC_Structured_Data(); $WC_Structured_Data->generate_review_data( $comment );
- $comment(WP_Comment) (required)
- Comment data.
WC_Structured_Data::generate_review_data() WC Structured Data::generate review data code WC 10.6.2
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 ) );
}