skip to Main Content

I am working on woocommerce and i am trying to limit the users to specify “only letters” in first and last name field in Myaccount page.What kind of hook should i want to add in functions.php?

2

Answers


  1. Chosen as BEST ANSWER

    I got a solution

    reference

    add_action('woocommerce_process_myaccount_field_billing_last_name','billing_last_name_field_validation' );
    function billing_last_name_field_validation(  ){
       /* print_r($_POST);
        die;*/
    
    
       $value = $_POST['billing_last_name'];
        if (!preg_match("/^[a-zA-Z]+$/", $value) ){       
            wc_add_notice( __( '<strong>Lastname should contain only letters</strong>' ), 'error' );
        }
        return $value; 
    }
    

  2. You can use your function.php and hook below code.

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields( $fields ) {
    $fields['first_name']['placeholder'] = '21343';
    $fields['first_name']['label'] = 'name';
    $fields['first_name']['pattern'] = '[A-Za-z]';
    return $fields;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search