Automate customer phone number formatting to include area code

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
665 170 199
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
Shopify Partner
1160 95 142

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.

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
0 Likes