Automattic\WooCommerce\Internal\Fulfillments\Providers
AustraliaPostShippingProvider::try_parse_tracking_number
Try to parse an Australia Post tracking number.
Method of the class: AustraliaPostShippingProvider{}
No Hooks.
Returns
Array|null. An array with 'url' and 'ambiguity_score' if valid, null otherwise.
Usage
$AustraliaPostShippingProvider = new AustraliaPostShippingProvider(); $AustraliaPostShippingProvider->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.
AustraliaPostShippingProvider::try_parse_tracking_number() AustraliaPostShippingProvider::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;
}
$normalized = strtoupper( preg_replace( '/\s+/', '', $tracking_number ) );
if ( empty( $normalized ) ) {
return null;
}
$shipping_from = strtoupper( $shipping_from );
$shipping_to = strtoupper( $shipping_to );
// Australia Post ships only from Australia.
if ( 'AU' !== $shipping_from ) {
return null;
}
if ( $this->validate_country_pattern( $normalized, $shipping_from ) ) {
$confidence = self::TRACKING_PATTERNS[ $shipping_from ]['confidence'];
// Check digit validation for numeric formats.
if ( preg_match( '/^\d{11,13}$/', $normalized ) ) {
if ( FulfillmentUtils::validate_mod10_check_digit( $normalized ) ) {
$confidence = min( 98, $confidence + 8 );
}
}
// UPU S10 validation for international formats.
if ( preg_match( '/^[A-Z]{2}\d{7,9}AU$/', $normalized ) ) {
if ( FulfillmentUtils::check_s10_upu_format( $normalized ) ) {
$confidence = min( 98, $confidence + 8 );
}
}
// Service-specific confidence boosts.
if ( preg_match( '/^(EP|ST|MB)\d+/', $normalized ) ) {
$confidence = min( 95, $confidence + 5 );
}
// Boost confidence for domestic shipments.
if ( 'AU' === $shipping_to ) {
$confidence = min( 98, $confidence + 5 );
}
// Boost confidence for Asia-Pacific destinations.
$apac_destinations = array( 'NZ', 'SG', 'HK', 'JP', 'KR', 'TH', 'MY', 'ID', 'PH', 'VN', 'IN' );
if ( in_array( $shipping_to, $apac_destinations, true ) ) {
$confidence = min( 95, $confidence + 3 );
}
// Boost confidence for common destinations.
$common_destinations = array( 'US', 'GB', 'CA', 'DE', 'FR' );
if ( in_array( $shipping_to, $common_destinations, true ) ) {
$confidence = min( 93, $confidence + 2 );
}
return array(
'url' => $this->get_tracking_url( $normalized ),
'ambiguity_score' => $confidence,
);
}
return null;
}