Jump to content

Recommended Posts

I'm a Newbie of (seriously) advanced years and would appreciate a bit of help.

I have a metabox with 2 fields. First field is called tracking_number and the tracking number is entered manually. The second field is called tracking_url which is also entered manually.

The current code is as follows:-

// Examine the tracking url and return a provider name.
function dcwd_get_tracking_provider_from_url( $url ) {
    if ( strpos( $url, 'parcel.force.com' ) !== false ) {
        return 'Parcel Force';
    }
    if ( strpos( $url, 'royal.mail.com' ) !== false ) {
        return 'Royal Mail';
    }
    if ( strpos( $url, 'ups.com' ) !== false ) {
        return 'UPS';
    }
        
    // Unknown provider.
    return null;
}

I want to have the second field populated automatically based on examining the format of the tracking number in the tracking_number field. 
The format for the carriers I use are :-

Royal Mail = 21 alpha-numeric starting with 320..........
Parcel Force = 2 alpha followed by 7 digits 
UPS = 18 alpha- numeric starting with 1Z

Can someone oblige with the necessary adjustments, please?
 

Link to comment
https://forums.phpfreaks.com/topic/314482-examine-tracking-code-to-get-carrier/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.