• Resolved chandan115

    (@chandan115)


    Hi,

    I have to add a custom country code field on the Customer billing address portion before Phone field.

    I am able to add custom field but unable to add on a required portion

    Please assist me with information or any reference.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @chandan115,

    If you’ll take a look at the code snippets in this document, there is an option to set a field as required when adding it.

    https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-6

    In this snippet, it is set to 'required' => false, so you’d need to change that to true to make it required.

    
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         $fields['shipping']['shipping_phone'] = array(
            'label'     => __('Phone', 'woocommerce'),
        'placeholder'   => _x('Phone', 'placeholder', 'woocommerce'),
        'required'  => false,
        'class'     => array('form-row-wide'),
        'clear'     => true
         );
    
         return $fields;
    }
    

    Take a look at that and see if you can adapt your custom field so it is required.

    Cheers,

    Howdy @chandan115,

    It’s been a while since we heard from you, so I’m marking this thread resolved. Hopefully, you’ve been able to resolve this, but if you haven’t, please let open up a new topic and we’ll be happy to help out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Custom field to Edit profile page on admin panel’ is closed to new replies.