Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/blocksy-companion-pro   php

Repository URL to install this package:

Version: 1.8.76 

/ extensions / product-reviews / helpers.php

<?php

function blocksy_get_product_review_overall_score($post_id = null) {
	if (! $post_id) {
		global $post;
		$post_id = $post->ID;
	}

	$atts = blocksy_get_post_options($post_id, [
		'meta_id' => 'blocksy_product_review_options'
	]);

	$scores = blocksy_akg('scores', $atts, []);

	if (empty($scores)) {
		return '';
	}

	$output = '<div class="ct-overall-score-layer">';

	$avg_score = apply_filters(
		'blocksy:ext:product-reviews:overall-score',
		round(array_reduce($scores, function ($carry, $score) {
			return $carry + floatval($score['score']);
		}, 0) / count($scores) * 10) / 10,
		$scores
	);

	$output .= '<span class="ct-score-label">';
	$output .= __('Rating', 'blocksy-companion');
	$output .= ':</span>';

	$output .= '<span class="ct-average-score">' . $avg_score . '/5</span>';

	$output .= '<div class="star-rating" role="img">';
	$width = (($avg_score / 5) * 100);
	$output .= '<span style="width: ' . $width . '%;"></span>';
	$output .= '</div>';

	$output .= '</div>';

	return $output;
}