Introduce wc_reviews_enabled, wc_review_ratings_enabled and wc_review_ratings_required as helper functions and update all places where options are accessed directly.
This commit is contained in:
parent
7b3fb815c9
commit
f3d9eeeef3
|
@ -146,7 +146,7 @@ class WC_Comments {
|
|||
*/
|
||||
public static function check_comment_rating( $comment_data ) {
|
||||
// If posting a comment (not trackback etc) and not logged in.
|
||||
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['rating'], $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['rating'] ) && '' === $comment_data['comment_type'] && 'yes' === get_option( 'woocommerce_enable_review_rating' ) && 'yes' === get_option( 'woocommerce_review_rating_required' ) ) { // WPCS: input var ok, CSRF ok.
|
||||
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['rating'], $comment_data['comment_type'] ) && 'product' === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['rating'] ) && '' === $comment_data['comment_type'] && wc_review_ratings_enabled() && wc_review_ratings_required() ) { // WPCS: input var ok, CSRF ok.
|
||||
wp_die( esc_html__( 'Please rate the product.', 'woocommerce' ) );
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -471,7 +471,7 @@ class WC_Frontend_Scripts {
|
|||
case 'wc-single-product':
|
||||
$params = array(
|
||||
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
|
||||
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
|
||||
'review_rating_required' => wc_review_ratings_required() ? 'yes' : 'no',
|
||||
'flexslider' => apply_filters(
|
||||
'woocommerce_single_product_carousel_options', array(
|
||||
'rtl' => is_rtl(),
|
||||
|
|
|
@ -261,7 +261,7 @@ class WC_Structured_Data {
|
|||
$markup['offers'] = array( apply_filters( 'woocommerce_structured_data_product_offer', $markup_offer, $product ) );
|
||||
}
|
||||
|
||||
if ( $product->get_review_count() && 'yes' === get_option( 'woocommerce_enable_review_rating' ) ) {
|
||||
if ( $product->get_review_count() && wc_review_ratings_enabled() ) {
|
||||
$markup['aggregateRating'] = array(
|
||||
'@type' => 'AggregateRating',
|
||||
'ratingValue' => $product->get_average_rating(),
|
||||
|
|
|
@ -418,3 +418,33 @@ function wc_post_content_has_shortcode( $tag = '' ) {
|
|||
|
||||
return is_singular() && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if reviews are enabled.
|
||||
*
|
||||
* @since 3.5.4
|
||||
* @return bool
|
||||
*/
|
||||
function wc_reviews_enabled() {
|
||||
return 'yes' === get_option( 'woocommerce_enable_reviews' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if reviews ratings are enabled.
|
||||
*
|
||||
* @since 3.5.4
|
||||
* @return bool
|
||||
*/
|
||||
function wc_review_ratings_enabled() {
|
||||
return wc_reviews_enabled() && 'yes' === get_option( 'woocommerce_enable_review_rating' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if review ratings are required.
|
||||
*
|
||||
* @since 3.5.4
|
||||
* @return bool
|
||||
*/
|
||||
function wc_review_ratings_required() {
|
||||
return 'yes' === get_option( 'woocommerce_review_rating_required' );
|
||||
}
|
||||
|
|
|
@ -1324,7 +1324,7 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
|
|||
unset( $catalog_orderby_options['menu_order'] );
|
||||
}
|
||||
|
||||
if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) {
|
||||
if ( ! wc_review_ratings_enabled() ) {
|
||||
unset( $catalog_orderby_options['rating'] );
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
global $product;
|
||||
|
||||
if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) || 'no' === get_option( 'woocommerce_enable_reviews' ) ) {
|
||||
if ( ! wc_review_ratings_enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.6.0
|
||||
* @version 3.5.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -31,7 +31,7 @@ if ( ! comments_open() ) {
|
|||
<h2 class="woocommerce-Reviews-title">
|
||||
<?php
|
||||
$count = $product->get_review_count();
|
||||
if ( $count && get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
|
||||
if ( $count && wc_review_ratings_enabled() ) {
|
||||
/* translators: 1: reviews count 2: product name */
|
||||
$reviews_title = sprintf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );
|
||||
echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $product ); // WPCS: XSS ok.
|
||||
|
@ -98,7 +98,7 @@ if ( ! comments_open() ) {
|
|||
$comment_form['must_log_in'] = '<p class="must-log-in">' . sprintf( esc_html__( 'You must be %slogged in%S to post a review.', 'woocommerce' ), '<a href="' . esc_url( $account_page_url ) . '">', '</a>' ) . '</p>';
|
||||
}
|
||||
|
||||
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
|
||||
if ( wc_review_ratings_enabled() ) {
|
||||
$comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . '</label><select name="rating" id="rating" required>
|
||||
<option value="">' . esc_html__( 'Rate…', 'woocommerce' ) . '</option>
|
||||
<option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option>
|
||||
|
|
|
@ -12,16 +12,16 @@
|
|||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.1.0
|
||||
* @version 3.5.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
global $product;
|
||||
|
||||
if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) {
|
||||
if ( ! wc_review_ratings_enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ $average = $product->get_average_rating();
|
|||
if ( $rating_count > 0 ) : ?>
|
||||
|
||||
<div class="woocommerce-product-rating">
|
||||
<?php echo wc_get_rating_html( $average, $rating_count ); ?>
|
||||
<?php echo wc_get_rating_html( $average, $rating_count ); // ?>
|
||||
<?php if ( comments_open() ) : ?><a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*
|
||||
* @see https://docs.woocommerce.com/document/template-structure/
|
||||
* @package WooCommerce/Templates
|
||||
* @version 3.1.0
|
||||
* @version 3.5.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -22,6 +22,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
global $comment;
|
||||
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
|
||||
|
||||
if ( $rating && 'yes' === get_option( 'woocommerce_enable_review_rating' ) ) {
|
||||
if ( $rating && wc_review_ratings_enabled() ) {
|
||||
echo wc_get_rating_html( $rating );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue