mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/73861428/woo-commerce-fist-last-name-field-restrict-numbers-from-being-used
10 lines
444 B
Text
10 lines
444 B
Text
add_action('woocommerce_after_checkout_validation', function ( $fields, $errors ) {
|
|
|
|
if (!preg_match('/^[a-zA-Z]+$/', $fields['billing_first_name'])) {
|
|
$errors->add('billing_first_name', 'First name must contain only alphabetic characters');
|
|
}
|
|
|
|
if (!preg_match('/^[a-zA-Z]+$/', $fields['billing_last_name'])) {
|
|
$errors->add('billing_last_name', 'Last name must contain only alphabetic characters');
|
|
}
|
|
}, 10, 2);
|