WordPress at Your Fingertips
function is not described

WC_Comments::validate_product_review_verified_owners() public WC 1.0

Validate product reviews if requires a verified owner.

{} It's a method of the class: WC_Comments{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_Comments::validate_product_review_verified_owners( $comment_post_id );
$comment_post_id(int) (required)
Post ID.

Code of WC_Comments::validate_product_review_verified_owners() WC 5.6.0

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,
		)
	);
}