The WPSSO JSON Premium add-on fattempts to detect aggregate rating values for supported e-Commerce products like WooCommerce. If your theme or another 3rd party plugin provides custom fields (aka post meta) for aggregate ratings, you may hook a WPSSO JSON Premium filter to modify the default values. Here’s an example using the ‘average_review’ and ‘count_review’ post meta.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
add_filter( 'wpsso_json_prop_https_schema_org_aggregaterating', 'custom_aggregaterating', 10, 2 ); function custom_aggregaterating( array $rating, array $mod ) { if ( $mod[ 'is_post' ] && $mod[ 'id' ] ) { // Check if this is a valid post. $rating_average = get_post_meta( $mod[ 'id' ], 'average_review', true ); $rating_count = get_post_meta( $mod[ 'id' ], 'count_review', true ); $rating[ 'ratingValue' ] = number_format( (float) $rating_average, '2', '.', '' ); $rating[ 'reviewCount' ] = (int) $rating_count; } return $rating; } |