Skip to content

Instantly share code, notes, and snippets.

@jorgejaramillo
Forked from mikejolley/title.php
Created April 13, 2012 03:45
Show Gist options
  • Save jorgejaramillo/2373505 to your computer and use it in GitHub Desktop.
Save jorgejaramillo/2373505 to your computer and use it in GitHub Desktop.
WooCommerce - Calificación y número de comentarios debajo del título.
<?php
/**
* Single Product Title
*/
?>
<h1 itemprop="name" class="product_title page-title"><?php the_title(); ?></h1>
<?php
global $wpdb, $post;
$count = $wpdb->get_var("
SELECT COUNT(meta_value) FROM $wpdb->commentmeta
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
WHERE meta_key = 'rating'
AND comment_post_ID = $post->ID
AND comment_approved = '1'
AND meta_value > 0
");
$rating = $wpdb->get_var("
SELECT SUM(meta_value) FROM $wpdb->commentmeta
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
WHERE meta_key = 'rating'
AND comment_post_ID = $post->ID
AND comment_approved = '1'
");
if ( $count > 0 ) {
$average = number_format($rating / $count, 2);
echo '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">';
echo '<div class="star-rating" title="'.sprintf(__('Rated %s out of 5', 'woocommerce'), $average).'"><span style="width:'.($average*16).'px"><span itemprop="ratingValue" class="rating">'.$average.'</span> '.__('out of 5', 'woocommerce').'</span></div>';
echo '<p>'.sprintf( _n('%s review', '%s reviews', $count, 'woocommerce'), '<span itemprop="ratingCount" class="count">'.$count.'</span>' ).'</p></div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment