Skip to content

Commit

Permalink
Options to enable/disable ratings. Closes woocommerce#847.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Mar 27, 2012
1 parent a3e2d8d commit ad499d1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
23 changes: 23 additions & 0 deletions admin/woocommerce-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,30 @@
),

array( 'type' => 'sectionend', 'id' => 'product_data_options' ),

array( 'name' => __( 'Product Reviews', 'woocommerce' ), 'type' => 'title', 'desc' => __('The following options affect product reviews (comments).', 'woocommerce'), 'id' => 'product_review_options' ),

array(
'name' => __( 'Ratings', 'woocommerce' ),
'desc' => __( 'Enable the star rating field on the review form', 'woocommerce' ),
'id' => 'woocommerce_enable_review_rating',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),

array(
'desc' => __( 'Ratings are required to leave a review', 'woocommerce' ),
'id' => 'woocommerce_review_rating_required',
'std' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
),

array( 'type' => 'sectionend', 'id' => 'product_review_options' ),

array( 'name' => __( 'Pricing Options', 'woocommerce' ), 'type' => 'title', 'desc' => __('The following options affect how prices are displayed on the frontend.', 'woocommerce'), 'id' => 'pricing_options' ),

array(
Expand Down
2 changes: 1 addition & 1 deletion assets/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jQuery(document).ready(function($) {
$('#review_form #submit').live('click', function(){
var rating = $('#rating').val();

if (!rating) {
if ( $('#rating').size() > 0 && !rating && woocommerce_params.review_rating_required == 'yes' ) {
alert(woocommerce_params.required_rating_text);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/woocommerce.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Allow shortcodes in excerpts
* Feature - Update/set order dates
* Feature - 'Invoice' for completed/pending emails re-sends download links etc
* Feature - Option to enable/disable review star rating
* Tweak - get order number function complete with filter
* Tweak - View cart link in 'you already have this in your cart' message
* Tweak - When viewing a product, give shop menu item a class
Expand Down
35 changes: 21 additions & 14 deletions templates/single-product-reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
AND comment_approved = '1'
");

if ( $count>0 ) :
if ( $count > 0 ) :

$average = number_format($rating / $count, 2);

Expand Down Expand Up @@ -71,7 +71,7 @@

echo '</div><div id="review_form_wrapper"><div id="review_form">';

comment_form(array(
$comment_form = array(
'title_reply' => $title_reply,
'comment_notes_before' => '',
'comment_notes_after' => '',
Expand All @@ -83,18 +83,25 @@
),
'label_submit' => __('Submit Review', 'woocommerce'),
'logged_in_as' => '',
'comment_field' => '
<p class="comment-form-rating"><label for="rating">' . __('Rating', 'woocommerce') .'</label><select name="rating" id="rating">
<option value="">'.__('Rate...', 'woocommerce').'</option>
<option value="5">'.__('Perfect', 'woocommerce').'</option>
<option value="4">'.__('Good', 'woocommerce').'</option>
<option value="3">'.__('Average', 'woocommerce').'</option>
<option value="2">'.__('Not that bad', 'woocommerce').'</option>
<option value="1">'.__('Very Poor', 'woocommerce').'</option>
</select></p>
<p class="comment-form-comment"><label for="comment">' . __( 'Your Review', 'woocommerce' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>'
. $woocommerce->nonce_field('comment_rating', true, false)
));
'comment_field' => ''
);

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

$comment_form['comment_field'] = '<p class="comment-form-rating"><label for="rating">' . __('Rating', 'woocommerce') .'</label><select name="rating" id="rating">
<option value="">'.__('Rate...', 'woocommerce').'</option>
<option value="5">'.__('Perfect', 'woocommerce').'</option>
<option value="4">'.__('Good', 'woocommerce').'</option>
<option value="3">'.__('Average', 'woocommerce').'</option>
<option value="2">'.__('Not that bad', 'woocommerce').'</option>
<option value="1">'.__('Very Poor', 'woocommerce').'</option>
</select></p>';

}

$comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . __( 'Your Review', 'woocommerce' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>' . $woocommerce->nonce_field('comment_rating', true, false);

comment_form( $comment_form );

echo '</div></div>';

Expand Down
8 changes: 4 additions & 4 deletions woocommerce-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,8 @@ function woocommerce_products_rss_feed() {
function woocommerce_add_comment_rating($comment_id) {
if ( isset($_POST['rating']) ) :
global $post;
if (!$_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0) $_POST['rating'] = 5;
add_comment_meta( $comment_id, 'rating', esc_attr($_POST['rating']), true );
if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) return;
add_comment_meta( $comment_id, 'rating', (int) esc_attr($_POST['rating']), true );
delete_transient( 'wc_average_rating_' . esc_attr($post->ID) );
endif;
}
Expand All @@ -1254,10 +1254,10 @@ function woocommerce_check_comment_rating($comment_data) {
global $woocommerce;

// If posting a comment (not trackback etc) and not logged in
if ( isset($_POST['rating']) && !$woocommerce->verify_nonce('comment_rating') )
if ( isset( $_POST['rating'] ) && ! $woocommerce->verify_nonce('comment_rating') )
wp_die( __('You have taken too long. Please go back and refresh the page.', 'woocommerce') );

elseif ( isset($_POST['rating']) && empty($_POST['rating']) && $comment_data['comment_type']== '' ) {
elseif ( isset( $_POST['rating'] ) && empty( $_POST['rating'] ) && $comment_data['comment_type'] == '' && get_option('woocommerce_review_rating_required') == 'yes' ) {
wp_die( __('Please rate the product.', 'woocommerce') );
exit;
}
Expand Down
1 change: 1 addition & 0 deletions woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ function frontend_scripts() {
'select_state_text' => __('Select an option&hellip;', 'woocommerce'),
'required_text' => esc_attr__( 'required', 'woocommerce' ),
'required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
'review_rating_required' => get_option('woocommerce_review_rating_required'),
'plugin_url' => $this->plugin_url(),
'ajax_url' => (!is_ssl()) ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'),
'get_variation_nonce' => wp_create_nonce("get-variation"),
Expand Down

0 comments on commit ad499d1

Please sign in to comment.