Automattic\WooCommerce\Internal\ProductFeed\Mapping
UcpProductMapper::build_rating
Build product rating.
Method of the class: UcpProductMapper{}
No Hooks.
Returns
array|null.
Usage
// private - for code of main (parent) class only $result = $this->build_rating( $item );
- $item(array) (required)
- Store API item response.
UcpProductMapper::build_rating() UcpProductMapper::build rating code WC 11.3.0
private function build_rating( array $item ) {
$average = (float) $item['average_rating'];
if ( $average <= 0 ) {
return null;
}
$rating = array(
'value' => $average,
'scale_min' => 1,
'scale_max' => 5,
);
$count = (int) $item['review_count'];
if ( $count > 0 ) {
$rating['count'] = $count;
}
return $rating;
}