Add new fields at the billing address woocommerce

I want to edit my billing address at my website, where i need to add and delete some others in my account page, which code shall I edit?

Thank you in advanced

Related posts

Leave a Reply

3 comments

  1. Can you please check below code you can add new custom field example.

    add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
    
    function custom_woocommerce_billing_fields( $fields ) {
    
       $fields['billing']['billing_options'] = array(
        'label'       => __('Custom Field', 'woocommerce'),             // Add custom field label
        'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'),  // Add custom field placeholder
        'required'    => false,             // if field is required or not
        'clear'       => false,             // add clear or not
        'type'        => 'text',                // add field type
        'class'       => array('own-css-name')      // add class name
        );
    
     return $fields;
    }
    
  2. To delete an existing field, country for example:

    add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
    function custom_override_billing_fields( $fields ) {
      unset($fields['billing_country']);
      return $fields;
    }
    
  3. maybe the best way use woocommerce_default_address_fields – is it ?
    for example as
    #5447232

    
    add_filter( 'woocommerce_default_address_fields', 'add_MyNewOption_address' );
    
    function add_MyNewOption_address( $fields ) {
    
       $fields['MyNewOption'] = array(
        'label'       => __('Custom Field', 'woocommerce'),             // Add custom field label
        'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'),  // Add custom field placeholder
        'required'    => false,             // if field is required or not
        'clear'       => false,             // add clear or not
        'type'        => 'text',                // add field type
        'class'       => array('own-css-name')      // add class name
        );
    
     return $fields;
    }