Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danichim/8bf1c05322daf2528d1e918cbfc332b5 to your computer and use it in GitHub Desktop.
Save danichim/8bf1c05322daf2528d1e918cbfc332b5 to your computer and use it in GitHub Desktop.
validate length billing phone and shipping phone woocommerce
add_action('woocommerce_checkout_process', 'check_phone_number_length');
function check_phone_number_length() {
global $woocommerce;
if ( ! (preg_match('/^[0-9]{10}$/D', $_POST['billing_phone'] ))){
wc_add_notice( "<strong>Telefon facturare</strong> Număr incorect ! Trebuie să conțină 10 cifre" ,'error' );
}
if (isset($_POST['shipping_phone']) && !empty($_POST['shipping_phone'])) {
if ( ! (preg_match('/^[0-9]{10}$/D', $_POST['shipping_phone'] ))){
wc_add_notice( "<strong>Telefon livrare</strong> Număr incorect ! Trebuie să conțină 10 cifre" ,'error' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment