Automattic\WooCommerce\Internal\OrderReviews
SubmissionHandler::has_rejected_review
Whether a moderator already marked this exact order/product/variation review as spam or trash. Reviews the comment pipeline auto-rejected (tagged with AUTO_REJECTED_META_KEY) are excluded, so an automatic verdict does not lock the customer out of resubmitting a clean review.
Method of the class: SubmissionHandler{}
No Hooks.
Returns
bool.
Usage
$result = SubmissionHandler::has_rejected_review( $order, $product_id, $variation_id ): bool;
- $order(WC_Order) (required)
- Order being reviewed.
- $product_id(int) (required)
- Parent product id.
- $variation_id(int) (required)
- Variation id (0 for simple products).
SubmissionHandler::has_rejected_review() SubmissionHandler::has rejected review code WC 11.1.2
private static function has_rejected_review( WC_Order $order, int $product_id, int $variation_id ): bool {
$email = $order->get_billing_email();
if ( '' === $email ) {
return false;
}
$comments = get_comments(
array(
'post_id' => $product_id,
'author_email' => $email,
'type' => 'review',
'status' => array( 'spam', 'trash' ),
'number' => 1,
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- bounded by post_id + author_email.
'relation' => 'AND',
array(
'key' => ItemEligibility::ORDER_META_KEY,
'value' => (string) $order->get_id(),
),
array(
// Only a moderator's verdict is final; skip pipeline auto-rejections.
'key' => self::AUTO_REJECTED_META_KEY,
'compare' => 'NOT EXISTS',
),
array(
'relation' => 'OR',
array(
'key' => ItemEligibility::VARIATION_META_KEY,
'value' => (string) $variation_id,
),
array(
// Pre-10.9.0 reviews have no VARIATION_META_KEY row at all.
'key' => ItemEligibility::VARIATION_META_KEY,
'compare' => 'NOT EXISTS',
),
),
),
)
);
return is_array( $comments ) && ! empty( $comments );
}