Automattic\WooCommerce\Internal\Fulfillments\Providers
EvriHermesShippingProvider::try_parse_tracking_number
Try to parse an Evri tracking number.
Method of the class: EvriHermesShippingProvider{}
No Hooks.
Returns
Array|null. An array with 'url' and 'ambiguity_score' if valid, null otherwise.
Usage
$EvriHermesShippingProvider = new EvriHermesShippingProvider(); $EvriHermesShippingProvider->try_parse_tracking_number( $tracking_number, $shipping_from, $shipping_to ): ?array;
- $tracking_number(string) (required)
- The tracking number to parse.
- $shipping_from(string) (required)
- The country code of the shipping origin.
- $shipping_to(string) (required)
- The country code of the shipping destination.
EvriHermesShippingProvider::try_parse_tracking_number() EvriHermesShippingProvider::try parse tracking number code WC 10.3.3
public function try_parse_tracking_number(
string $tracking_number,
string $shipping_from,
string $shipping_to
): ?array {
if ( empty( $tracking_number ) || empty( $shipping_from ) || empty( $shipping_to ) ) {
return null;
}
// Check if this provider can handle this shipping route.
if ( ! $this->can_ship_from_to( $shipping_from, $shipping_to ) ) {
return null;
}
$normalized = strtoupper( preg_replace( '/\s+/', '', $tracking_number ) );
if ( empty( $normalized ) ) {
return null;
}
// 1. Check for main 16-digit and legacy Evri/Hermes formats.
foreach ( self::MAIN_PATTERNS as $pattern ) {
if ( preg_match( $pattern, $normalized ) ) {
$confidence = 90;
// Boost for UK shipments.
if ( 'GB' === $shipping_from ) {
$confidence = min( 98, $confidence + 2 );
}
return array(
'url' => $this->get_tracking_url( $normalized ),
'ambiguity_score' => $confidence,
);
}
}
// 2. Check for 8-digit calling card number.
if ( preg_match( self::CALLING_CARD_PATTERN, $normalized ) ) {
return array(
'url' => $this->get_tracking_url( $normalized ),
'ambiguity_score' => 80,
);
}
// 3. Check for legacy/fallback patterns (lower confidence).
foreach ( self::LEGACY_PATTERNS as $pattern ) {
if ( preg_match( $pattern, $normalized ) ) {
$confidence = 75;
// Boost for UK shipments.
if ( 'GB' === $shipping_from ) {
$confidence = min( 95, $confidence + 15 );
}
return array(
'url' => $this->get_tracking_url( $normalized ),
'ambiguity_score' => $confidence,
);
}
}
return null;
}