Billing First Name Should Be Alphabetic

add_filter(‘woocommerce_billing_fields’, ‘custom_woocommerce_billing_fields’);

function custom_woocommerce_billing_fields( $fields )

Read More

{

$fields[‘billing_first_name’][‘required’] = false;

return $fields;

}

I want to make First and Last name should be alphabetic only. Right now it’s accepting numbers also.

Help will be much appreciated. I also want to limit text of review in cart.

Regards

Related posts

2 comments

  1. $('#billing_first_name').on('input',function(){ 
        var node = $(this);
        node.val(node.val().replace(/[^a-z]/g,'') ); }
    );
    

    Adding this jQuery will work.! You can add for others fields too.

  2. You have to add fields by custom method then use follow script for alphabetic textbox:

    add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
    
    function custom_override_checkout_fields($fields)
    {
    $fields['billing']['billing_first_name'] = array(
        'label'     => __('First name', 'woocommerce'),
        'placeholder'   => _x('First name', 'placeholder', 'woocommerce'),
        'required'    => false,
        'clear'       => false,
        'type'        => 'text',
        'class'       => array(
                        'alpha'
       )
    );
    

    and same for billing_last_name,

    use all of scripts in active theme functions.php

    Actually woo-commerce does not give us this functionality. You have to use your custom jquery or javascript. This might help you

    You should call this script under wp_head hook

    add_action('wp_head', ' alphabet_only ');
    
    function alphabet_only() {
    ?>
        <script type="text/javascript">
    $('.alpha').bind('keyup blur',function(){ 
        var node = $(this);
        node.val(node.val().replace(/[^a-z]/g,'') ); }
    );
    </script>
    <?php
    }
    

    That’s it.

Comments are closed.