WC_Structured_Data::generate_review_data()publicWC 1.0

Generates Review structured data.

Hooked into woocommerce_review_meta hook.

Метод класса: WC_Structured_Data{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

$WC_Structured_Data = new WC_Structured_Data();
$WC_Structured_Data->generate_review_data( $comment );
$comment(WP_Comment) (обязательный)
Comment data.

Код WC_Structured_Data::generate_review_data() WC 8.7.0

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 ) );
}