mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/53909349/allow-only-letter-on-specific-woocommerce-checkout-fields/
23 lines
771 B
Text
23 lines
771 B
Text
add_action( 'wp_footer', 'checkout_field_name_validator_script');
|
|
function checkout_field_name_validator_script() {
|
|
// Only on checkout page
|
|
if( ! ( is_checkout() && ! is_wc_endpoint_url() ) ) return;
|
|
?>
|
|
<script>
|
|
jQuery(function($){
|
|
var b = '#billing_', s = '#shipping_', f = 'first_', l = 'last_',
|
|
n = 'name', p = 'postcode', c = ',';
|
|
|
|
// Postcode fields
|
|
$(b+p+c+s+p).bind('keyup blur',function(){
|
|
$(this).val($(this).val().replace(/[^0-9]+/,''));
|
|
});
|
|
|
|
// First and Last name fields
|
|
$(b+f+n+c+b+l+n+c+s+f+n+c+s+l+n).bind('keyup blur',function(){
|
|
$(this).val($(this).val().replace(/[0-9.,;:?!]+/,''));
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|