0 ) { $byId = \wc_get_order( $intId ); if ( $byId instanceof WC_Order && (int) $byId->get_id() === $intId ) { return $byId; } } } if ( ! \function_exists( 'wc_get_orders' ) ) { return null; } $matches = \wc_get_orders( [ 'limit' => 1, 'return' => 'objects', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- single-row lookup with limit 1, indexed meta key. 'meta_query' => [ [ 'key' => '_order_number', 'value' => $number, 'compare' => '=', ], ], ] ); if ( ! is_array( $matches ) || ! isset( $matches[0] ) || ! ( $matches[0] instanceof WC_Order ) ) { return null; } $candidate = $matches[0]; $actualMeta = (string) $candidate->get_meta( '_order_number', true ); if ( $actualMeta === '' || $actualMeta !== $number ) { return null; } return $candidate; } public function emailMatches( WC_Order $order, string $email ): bool { $billing = (string) $order->get_billing_email(); if ( $billing === '' ) { return false; } return strtolower( trim( $billing ) ) === strtolower( trim( $email ) ); } }