Skip to content

Instantly share code, notes, and snippets.

@Kodzhesyan
Created December 17, 2021 00:21
Show Gist options
  • Save Kodzhesyan/3f4bec080e949401d21b8134a7b023c9 to your computer and use it in GitHub Desktop.
Save Kodzhesyan/3f4bec080e949401d21b8134a7b023c9 to your computer and use it in GitHub Desktop.
Custom validation for Billing Phone checkout field - WooCommerce
// Custom validation for Billing Phone checkout field
add_action('woocommerce_checkout_process', 'custom_validate_billing_phone');
function custom_validate_billing_phone() {
$is_correct = preg_match('/^[0-9]{10}$/', $_POST['billing_phone']);
if ( $_POST['billing_phone'] && !$is_correct) {
wc_add_notice( __( 'Напишите правильно свой номер телефона.<strong>Он должен состоять только из 10 цифр</strong>. Например: <strong>0990603439</strong>' ), 'error' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment