Automattic\WooCommerce\Internal\OrderReviews

SubmissionHandler::find_auto_rejected_review │ private static │ WC 1.0

The customer's own auto-rejected (spam/trash, tagged) review for this order/product/variation, if any, so a resubmission reuses that row instead of stacking a new one. Moderator verdicts (untagged) are not returned.

Method of the class: SubmissionHandler{}

No Hooks.

Returns

\WP_Comment|null.

Usage

$result = SubmissionHandler::find_auto_rejected_review( $order, $product_id, $variation_id ): ?\WP_Comment;
$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::find_auto_rejected_review() code WC 11.1.2

private static function find_auto_rejected_review( WC_Order $order, int $product_id, int $variation_id ): ?\WP_Comment {
	$email = $order->get_billing_email();
	if ( '' === $email ) {
		return null;
	}

	$comments = get_comments(
		array(
			'post_id'      => $product_id,
			'author_email' => $email,
			'type'         => 'review',
			'status'       => array( 'spam', 'trash' ),
			'number'       => 1,
			'orderby'      => 'comment_date_gmt',
			'order'        => 'DESC',
			'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(
					'key'     => self::AUTO_REJECTED_META_KEY,
					'compare' => 'EXISTS',
				),
				array(
					'relation' => 'OR',
					array(
						'key'   => ItemEligibility::VARIATION_META_KEY,
						'value' => (string) $variation_id,
					),
					array(
						'key'     => ItemEligibility::VARIATION_META_KEY,
						'compare' => 'NOT EXISTS',
					),
				),
			),
		)
	);

	if ( ! is_array( $comments ) || empty( $comments ) ) {
		return null;
	}

	$first = reset( $comments );
	return $first instanceof \WP_Comment ? $first : null;
}