Předvyplním předvolbu +420:
<?php
function gog_modify_checkout_fields($fields) {
$fields['billing']['billing_phone']['default'] = '+420';
$fields['billing']['billing_phone']['placeholder'] = '+420';
return $fields;
}
add_filter('woocommerce_checkout_fields' , 'gog_modify_checkout_fields');
Kontrola a případné doplnění předvolby +420:
jQuery(document).ready(function() {
jQuery('#billing_phone').focusout(function() {
var phone = jQuery(this).val();
phone = phone.replace(/[^0-9\+]/g, '');
if (phone.substr(0,4) == '+420') {
// ok
}
else if (phone.substr(0,5) == '00420') {
phone = phone.replace(/^00420/, '+420');
console.log(phone);
}
else {
phone = '+420' + phone;
}
jQuery(this).val(phone);
});
)};