WC_Comments::validate_product_review_verified_owners
Validate product reviews if requires a verified owner.
Метод класса: WC_Comments{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WC_Comments::validate_product_review_verified_owners( $comment_post_id );
- $comment_post_id(int) (обязательный)
- Post ID.
Код WC_Comments::validate_product_review_verified_owners() WC Comments::validate product review verified owners WC 10.6.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,
)
);
}