When running a WooCommerce store that serves international customers, collecting phone numbers in a standardized format can be challenging. Customers from different countries use various phone number formats, and without proper validation, you might end up with incomplete or incorrectly formatted contact information.
In this tutorial, I’ll show you how to implement an international phone input mask on your WooCommerce checkout page using the popular intl-tel-input library. This solution provides automatic phone number formatting, country detection, validation, and a user-friendly country selector with flags.
Phone Mask to WooCommerce Checkout
What you’ll get:
- Automatic phone number formatting based on the selected country
- Visual country flag dropdown for easy selection
- Real-time validation to ensure correct phone number format
- Preferred country (Ukraine in this example) set by default
- Clean, professional appearance that matches your checkout design
This implementation is perfect for store owners who want to improve data quality and enhance the checkout experience for their international customers.
add_action( 'wp_enqueue_scripts', 'ts_add_phone_mask' );
function ts_add_phone_mask() {
wp_enqueue_style( 'intltelinput', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.3/css/intlTelInput.min.css' );
wp_enqueue_script( 'intltelinput', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.3/js/intlTelInput-jquery.min.js', array( 'jquery' ), '', true );
}
// Initialize the phone mask script
add_action( 'wp_footer', 'ts_init_phone_mask' );
function ts_init_phone_mask() {
?>
<script>
jQuery( function( $ ) {
var $input = $( '#billing_phone' );
// 1. Ініціалізація через jQuery синтаксис
$input.intlTelInput({
preferredCountries: [ 'UA' ],
nationalMode: true,
formatOnDisplay: true,
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.3/js/utils.js"
});
// 2. Обмеження кількості символів
// Для України формат 0XX XXX XX XX — це 10 цифр.
// З урахуванням пробілів, які додає плагін, це близько 13-15 символів.
$input.on( 'keyup change', function() {
var intl = $input.intlTelInput("getNumber"); // Отримуємо повний номер +380...
// Отримуємо екземпляр плагіна для перевірки валідності
if ($input.val().length > 0) {
if ($input.intlTelInput("isValidNumber")) {
// Якщо номер валідний, можна заборонити подальше введення
// Або просто підсвітити зеленим
$input.removeClass('error').addClass('valid');
} else {
$input.removeClass('valid').addClass('error');
}
}
});
// Жорстке обмеження на введення лише цифр та довжину (запобігає спаму символами)
$input.attr('maxlength', '16');
});
</script>
<style>
.iti { width: 100%; }
.iti__country-list { z-index: 9999; } /* Щоб список країн не ховався під елементи чекауту */
input#billing_phone.error { border: 1px solid red !important; }
</style>
<?php
}
Conclusion
By implementing this international phone input mask, you’ve significantly improved your WooCommerce checkout experience. The intl-tel-input library handles the complex task of formatting and validating phone numbers across different countries, while your customers enjoy a smoother, more intuitive form-filling process.
Key benefits of this implementation:
- Better data quality – You’ll collect properly formatted phone numbers that are easier to use for shipping notifications and customer service
- Reduced cart abandonment – Clear validation feedback helps customers complete checkout faster
- Professional appearance – The country flag selector adds a polished, modern touch to your checkout page
- Flexibility – You can easily customize the preferred countries or validation rules to match your store’s target markets
Customization tips Add Phone Mask to WooCommerce:
- Change
preferredCountries: [ 'UA' ]to your primary market (e.g., ‘US’, ‘GB’, ‘CA’) - Adjust the
maxlengthvalue if you need to accommodate longer phone numbers - Modify the CSS to match your theme’s color scheme
If you serve customers from multiple countries, this simple addition to your functions.php file (or a custom plugin) can save hours of manual data cleanup and improve customer communication down the line.
Have you implemented phone validation on your WooCommerce store? Share your experience in the comments below!

