-
-
Save jorgejaramillo/2373505 to your computer and use it in GitHub Desktop.
WooCommerce - Calificación y número de comentarios debajo del título.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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