WC_Comments::validate_product_review_verified_owners()
Validate product reviews if requires a verified owner.
Method of the class: WC_Comments{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = WC_Comments::validate_product_review_verified_owners( $comment_post_id );
- $comment_post_id(int) (required)
- Post ID.
WC_Comments::validate_product_review_verified_owners() WC Comments::validate product review verified owners code WC 9.4.2
public static function validate_product_review_verified_owners( $comment_post_id ) { // Only validate if option is enabled. if ( 'yes' !== get_option( 'woocommerce_review_rating_verification_required' ) ) { return; } // Validate only products. if ( 'product' !== get_post_type( $comment_post_id ) ) { return; } // Skip if is a verified owner. if ( wc_customer_bought_product( '', get_current_user_id(), $comment_post_id ) ) { return; } wp_die( esc_html__( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ), esc_html__( 'Reviews can only be left by "verified owners"', 'woocommerce' ), array( 'code' => 403, ) ); }