TrapBarn Posted January 30, 2022 Share Posted January 30, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/314482-examine-tracking-code-to-get-carrier/ Share on other sites More sharing options...
ginerjm Posted January 30, 2022 Share Posted January 30, 2022 All I see is a function that gives you something based upon what is in the url argument. What is your definition of a "metabox"? Is this some displayable tag or an input tag? ?? Quote Link to comment https://forums.phpfreaks.com/topic/314482-examine-tracking-code-to-get-carrier/#findComment-1593732 Share on other sites More sharing options...
ginerjm Posted January 30, 2022 Share Posted January 30, 2022 PS - I would use the case-insensitive version of this function: stripos. Never know when the url might be different. Quote Link to comment https://forums.phpfreaks.com/topic/314482-examine-tracking-code-to-get-carrier/#findComment-1593739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.