Automate customer phone number formatting to include area code

Highlighted
New Member
1 0 0

I have an Australian client that requires customers to enter their phone number in a certain format when they go through the checkout process so the delivery drivers can send tracking notifications to them. The delivery drivers require the phone number to begin with +61 (Australian mobile area code) and they can't have any spaces or dashes in the number, but most customers enter this data in the standard local format used in Australia - i.e. phone numbers starting with '04' and adding spaces throughout, such as '0411 234 456'.

 

My client would like to automate the process of converting the incorrect format of numbers into the correct format that they require.

 

Examples of the required automations are listed below:

  • '0411 123 456' will be automatically converted to '+61411123456'
  • '0411123456' will be automatically converted to '+61411123456'
  • '61 411 123 456' will be automatically converted to '+61411123456'
  • '61411123456' will automatically add a '+' sign at the beginning

Does anyone know of a solution that would allow us to create this type of automation in customer records / phone numbers? Any help or advice would be greatly appreciated! 

 

Thanks,

 

Ben

0 Likes
Shopify Expert
667 170 220
This is Evita from On The Map.
 
You will need to use jquery for this. 
// This is and example of the users phone number, you will need to get them by jquery selector
let phone = '0411 123 456';

// This will remove the white space if the number has any.
phone.replace(' ', '');

// If first character ir 0 it will remove the 0
if (phone.charAt(0) === 0) {
phone.substring(1, phone.length);
phone = "+61" + phone;
}

// If character doesn't contains +, but has 6 alredy in front, it will ad the plus sign
if (phone.charAt(0) !== + && phone.charAt(1) === 6) {
phone = "+" + phone;
}

// If character doesn't contains + and doesn't have 6 in front it will add +61
if (phone.charAt(0) !== + && phone.charAt(1) !== 6) {
phone = "+61" + phone;
}

console.log(phone);
return phone;
 
Best,
Evita
 
 
On The Map Marketing | Developing custom Shopify Sites & Apps is our thing

- Install our latest app Accessibly - Makes your store accessible for everyone, helps to avoid fines
- Inc 5000 | Shopify Parners | 20+ stores launched | 300+ active clients
- Need help with your Shopify store? Reach out to us!
1 Like
Highlighted
Shopify Expert
1381 111 203

Hi @broberts11,

 

Well, this is possible for fixed number of codes. I mean, the area code should be known beforehand and will be hard-coded to do this formatting. 

Please feel free to reach out for further discussion.

0 Likes
Highlighted
Tourist
10 0 1

How did you go with this @broberts11 ? We have the same need.

0 Likes
Highlighted
New Member
1 0 0

Hi,

 

Do you happen to have a solution similar to this that actually strips or removes any time a user enters a phone number and including the '+' at the front? We need to drop this from all entries

0 Likes
Highlighted
Tourist
10 0 1

Hey Evita at @OTM .

 

Do you know if the solution you proposed will work in Shopify Advanced or is it limited to Shopify Plus?

 

Cheers,

 

Steve

0 Likes
Highlighted
New Member
3 0 0

Hi,

I tried to create a customer via customers.jon API but each time i provided a static data for phone it is creating a customer but with dynamic data (via a form) it is not working. 

for example +91XXXXXXXXXX working when +91 is fixed data and rest number is coming from form but it is not working when whole data is coming from form.

any idea where i am doing wrong?

0 Likes