Skip to content

Commit

Permalink
Move average rating outside of hidden tab. Closes woocommerce#3867.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Oct 31, 2013
1 parent 447b9d8 commit b4d1c76
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 23 deletions.
2 changes: 1 addition & 1 deletion assets/css/woocommerce.css

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion assets/css/woocommerce.less
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ p.demo_store {
}

/* Star rating */

.star-rating {
float: right;
overflow: hidden;
Expand Down Expand Up @@ -877,6 +876,16 @@ p.demo_store {
}
}

.woocommerce-product-rating {
line-height: 2em;
display: block;

.star-rating {
margin: .5em 4px 0 0;
float: left;
}
}

.products {
.star-rating {
display: block;
Expand Down
5 changes: 5 additions & 0 deletions assets/js/frontend/single-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jQuery(document).ready(function($) {
}
});

$('a.woocommerce-review-link').click(function() {
$('.reviews_tab a').click();
return true;
});

// Star ratings for comments
$('#rating').hide().before('<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2" href="#">2</a><a class="star-3" href="#">3</a><a class="star-4" href="#">4</a><a class="star-5" href="#">5</a></span></p>');

Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/single-product.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions includes/wc-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,19 @@ function woocommerce_template_single_title() {
woocommerce_get_template( 'single-product/title.php' );
}
}
if ( ! function_exists( 'woocommerce_template_single_rating' ) ) {

/**
* Output the product rating.
*
* @access public
* @subpackage Product
* @return void
*/
function woocommerce_template_single_rating() {
woocommerce_get_template( 'single-product/rating.php' );
}
}
if ( ! function_exists( 'woocommerce_template_single_price' ) ) {

/**
Expand Down
1 change: 1 addition & 0 deletions includes/wc-template-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
* @see woocommerce_template_single_sharing()
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Removed placeholder polyfill. Use this plugin to replace functionality if required: http://wordpress.org/plugins/html5-placeholder-polyfill/
* Tweak - Replaced all instances of &rarr; and &larr; in frontent using wc icon font plus .wc-forward and .wc-backward utility classes.
* Tweak - Add review form no longer opens in lightbox.
* Tweak - Move average rating outside of hidden tab for google #3867.
* Fix - Changed MyException to Exception in Checkout class as MyException class does not exist in WooCommerce
* Fix - Default cart widget styling on non-wc pages.
* Fix - Rounding for mijireh tax ex. price.
Expand Down
22 changes: 2 additions & 20 deletions templates/single-product-reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,9 @@

echo '<div id="comments">';

if ( get_option('woocommerce_enable_review_rating') == 'yes' ) {

$count = $product->get_rating_count();

if ( $count > 0 ) {

$average = $product->get_average_rating();

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 / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>';

echo '<h2>'.sprintf( _n('%s review for %s', '%s reviews for %s', $count, 'woocommerce'), '<span itemprop="ratingCount" class="count">'.$count.'</span>', get_the_title() ).'</h2>';

echo '</div>';

} else {

echo '<h2>'.__( 'Reviews', 'woocommerce' ).'</h2>';
if ( get_option('woocommerce_enable_review_rating') == 'yes' && ( $count = $product->get_rating_count() ) ) {

}
echo '<h2>' . sprintf( _n('%s review for %s', '%s reviews for %s', $count, 'woocommerce'), $count, get_the_title() ) . '</h2>';

} else {

Expand Down
31 changes: 31 additions & 0 deletions templates/single-product/rating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Single Product Rating
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.1.0
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $product;

if ( get_option( 'woocommerce_enable_review_rating' ) == 'no' )
return;

$count = $product->get_rating_count();
$average = $product->get_average_rating();

if ( $count > 0 ) : ?>

<div class="woocommerce-product-rating" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
<div class="star-rating" title="<?php printf( __( 'Rated %s out of 5', 'woocommerce' ), $average ); ?>">
<span style="width:<?php echo ( ( $average / 5 ) * 100 ); ?>%">
<strong itemprop="ratingValue" class="rating"><?php echo esc_html( $average ); ?></strong> <?php _e( 'out of 5', 'woocommerce' ); ?>
</span>
</div>
<a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $count, 'woocommerce' ), '<span itemprop="ratingCount" class="count">' . $count . '</span>' ); ?>)</a>
</div>

<?php endif; ?>

0 comments on commit b4d1c76

Please sign in to comment.