---
title: "How do you add a NIF or CIF field to WooCommerce 2.0?"
description: "In How do you configure VAT for the Canary Islands, Ceuta and Melilla in WooCommerce 2.0? we already promised you that we would explain how to add a NIF/CIF field to WooCommerce easily and simply, and although at first sight"
url: https://artprojectgroup.com/how-to-add-a-nif-or-cif-field-to-woocommerce-2-0
date: 2013-11-29
modified: 2026-10-02
author: "Art Project Group"
image: https://artprojectgroup.com/wp-content/uploads/2023/04/woocommerce-blog.webp
categories: ["Tutorials"]
tags: ["functions.php", "WooCommerce", "WordPress"]
type: post
lang: en-US
---

# How do you add a NIF or CIF field to WooCommerce 2.0?

[![Order form of the Herves-Vida online shop](https://artprojectgroup.com/wp-content/uploads/2013/11/formulario-de-pedido-de-la-tienda-virtual-de-herves-vida.webp)](https://artprojectgroup.com/wp-content/uploads/2013/11/formulario-de-pedido-de-la-tienda-virtual-de-herves-vida.webp)

In [How do you configure VAT for the Canary Islands, Ceuta and Melilla in WooCommerce 2.0?](/how-to-configure-vat-for-canary-islands-ceuta-and-melilla-in-woocommerce-2-0) we already promised you that we would explain how to add a NIF/CIF field to WooCommerce easily and simply, and although at first sight it may look as though it is neither easy nor simple, the truth is that it is, as long as we carry out all the steps we state for you below. Although around the Internet there are several partial solutions that are more or less effective, we have not found a complete one, so **APG** offers you the definitive solution for adding the NIF/CIF field to WooCommerce. As almost always when we get stuck into this kind of job, we have to modify the *functions.php* file of our WordPress child theme, and this time was not going to be any different. So we are going to explain one by one all the things that have to be added to the *functions.php* file. In the first place we are going to physically create the fields we need, we are going to lay them out and arrange them correctly for their entry, both in the shipping form and in the billing form, and we will also add the *Email Address* and *Phone* fields to the form with the shipping details:

Copy to clipboardSyntax Highlighter//We fix the default address
function address_fields( $fields ) {
$fields[ 'nif' ] = array(
'label' => __( 'CIF/NIF', 'woocommerce' ),
'placeholder' => _x( 'Enter the CIF/NIF', 'placeholder', 'woocommerce' ),
'required' => false,
'class' => array( 'form-row-last' ),
'clear' => true,
);

$fields[ 'company' ]\[ 'class' ]\[ 0 ] = 'form-row-first';
$fields[ 'city' ]\[ 'class' ]\[ 0 ] = 'form-row-first';
$fields[ 'state' ]\[ 'class' ]\[ 0 ] = 'form-row-last update_totals_on_change';
$fields[ 'postcode' ]\[ 'class' ]\[ 0 ] .= ' update_totals_on_change';

//We reorder the fields
$new_fields[ 'country' ] = $fields[ 'country' ];
$new_fields[ 'first_name' ] = $fields[ 'first_name' ];
$new_fields[ 'last_name' ] = $fields[ 'last_name' ];
$new_fields[ 'company' ] = $fields[ 'company' ];
$new_fields[ 'nif' ] = $fields[ 'nif' ];
$new_fields[ 'address_1' ] = $fields[ 'address_1' ];
$new_fields[ 'address_2' ] = $fields[ 'address_2' ];
$new_fields[ 'postcode' ] = $fields[ 'postcode' ];
$new_fields[ 'city' ] = $fields[ 'city' ];
$new_fields[ 'state' ] = $fields[ 'state' ];
if ( isset( $fields[ 'email' ] ) )$new_fields[ 'email' ] = $fields[ 'email' ];
if ( isset( $fields[ 'phone' ] ) )$new_fields[ 'phone' ] = $fields[ 'phone' ];

return $new_fields;
}
add_filter( 'woocommerce_default_address_fields', 'address_fields' );
Note that if we want it to come out correctly translated into each language we support in our shop, we recommend that you put the Spanish texts that appear in the *label* and *placeholder* options into English and translate the texts for each language. For that we can use a plugin such as CodeStyling Localization. The problem with this is that every time WooCommerce is updated we will lose all the modifications we have made to the translation files, which is why we have preferred to leave it in Spanish. Another thing that has to be taken into account is the *class* option, which can take 3 possible values:

- *form-row-wide*: will make the field take up the whole of the width available in the form.
- *form-row-first*: will make the field take up the first half of the width available in the form.
- *form-row-last*: will make the field take up the second half of the width available in the form.

The *class* option can also adopt the value *update_totals_on_change*, which we use to force the calculation of the shipping total, just as we explain in [How do you force the order total to update in WooCommerce?](/how-to-force-the-order-total-to-update-in-woocommerce). So we will have to play with these values so that our new field is embedded appropriately in our form. Also, as you can see, in our particular case we have modified the *Company Name* field and the *Town / City* field so that they adopt the *form-row-first* class and the *State / County* field so that it adopts the *form-row-last* class. You may have to customise this depending on the needs of your forms. Now we carry on by adding the new field to the forms with the billing and shipping details; we must also alter the default address format and the one specific to our language so that the new NIF/CIF field is shown throughout WooCommerce:

Copy to clipboardSyntax Highlighter//We add the NIF to the billing and shipping address
function add_nif_field_to_billing_address( $fields, $order ) {
$fields[ 'nif' ] = $order->order_custom_fields[ '_billing_nif' ]\[ 0 ];

return $fields;
}
add_filter( 'woocommerce_order_formatted_billing_address', 'add_nif_field_to_billing_address', 1, 2 );

function add_nif_field_to_shipping_address( $fields, $order ) {
$fields[ 'nif' ] = $order->order_custom_fields[ '_shipping_nif' ]\[ 0 ];

return $fields;
}
add_filter( 'woocommerce_order_formatted_shipping_address', 'add_nif_field_to_shipping_address', 1, 2 );

function billing_address_format( $fields, $argumentos ) {
$fields[ '{nif}' ] = $argumentos[ 'nif' ];
$fields[ '{nif_upper}' ] = strtoupper( $argumentos[ 'nif' ] );

return $fields;
}
add_filter( 'woocommerce_formatted_address_replacements', 'billing_address_format', 1, 2 );

//We reorder the fields of the default address
function localisation_address_format( $fields ) {
$fields[ 'default' ] = "{name}\n{company}\n{nif}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}";
$fields[ 'ES' ] = "{name}\n{company}\n{nif}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}";

return $fields;
}
add_filter( 'woocommerce_localisation_address_formats', 'localisation_address_format' );
If you use more languages, you will only have to go on adding them in the last function, altering its specific format so that it includes the field we have just created in the previous function. We now have almost everything ready. Now we are going to alter the form with the shipping details so that the newly added *Email Address* and *Phone* fields are shown as they should be. We are also going to fix a problem we have detected in the *Postcode / Zip* field, both in the form with the shipping details and in the form with the billing details. For that we are going to include these functions:

Copy to clipboardSyntax Highlighter//We fix the shipping form
function shipping_form( $fields ) {
$fields[ 'shipping_email' ] = array(
'label' => __( 'Email Address', 'woocommerce' ),
'required' => false,
'class' => array( 'form-row-first' ),
'validate' => array( 'email' ),
);
$fields[ 'shipping_phone' ] = array(
'label' => __( 'Phone', 'woocommerce' ),
'required' => true,
'class' => array( 'form-row-last' ),
'clear' => true,
);
$fields[ 'shipping_postcode' ] = array(
'label' => __( 'Postcode / Zip', 'woocommerce' ),
'placeholder' => __( 'Postcode / Zip', 'woocommerce' ),
'required' => true,
'class' => array( 'form-row-wide', 'address-field' ),
'clear' => true,
'custom_attributes' => array(
'autocomplete' => 'no'
)
);

return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'shipping_form' );

//We fix the billing form
function billing_form( $fields ) {
$fields[ 'billing_postcode' ] = array(
'label' => __( 'Postcode / Zip', 'woocommerce' ),
'placeholder' => __( 'Postcode / Zip', 'woocommerce' ),
'required' => true,
'class' => array( 'form-row-wide', 'address-field' ),
'clear' => true,
'custom_attributes' => array(
'autocomplete' => 'no'
)
);

return $fields;
}
add_filter( 'woocommerce_billing_fields', 'billing_form' );
In our case we have made only the *Phone* field required, although you can modify the *required* option by stating *true* or *false* as you need it. The forms and addresses that appear in *Users* and in *WooCommerce -> Order Details*, both in the *administration panel* of our WordPress, also have to be modified. We are going to achieve it by adding these three new functions:

Copy to clipboardSyntax Highlighter//Adds the CIF/NIF field to users
function add_fields_to_user_admin( $fields ) {
$fields[ 'billing' ]\[ 'fields' ]\[ 'billing_nif' ] = array(
'label' => __( 'CIF/NIF', 'woocommerce' ),
'description' => ''
);

$fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_nif' ] = array(
'label' => __( 'CIF/NIF', 'woocommerce' ),
'description' => ''
);
$fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_email' ] = array(
'label' => __( 'Email', 'woocommerce' ),
'description' => ''
);
$fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_phone' ] = array(
'label' => __( 'Telephone', 'woocommerce' ),
'description' => ''
);

//We reorder the fields
$new_fields[ 'billing' ]\[ 'title' ] = $fields[ 'billing' ]\[ 'title' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_first_name' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_first_name' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_last_name' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_last_name' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_company' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_company' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_nif' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_nif' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_address_1' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_address_1' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_address_2' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_address_2' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_postcode' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_postcode' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_city' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_city' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_state' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_state' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_country' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_country' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_phone' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_phone' ];
$new_fields[ 'billing' ]\[ 'fields' ]\[ 'billing_email' ] = $fields[ 'billing' ]\[ 'fields' ]\[ 'billing_email' ];

$new_fields[ 'shipping' ]\[ 'title' ] = $fields[ 'shipping' ]\[ 'title' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_first_name' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_first_name' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_last_name' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_last_name' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_company' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_company' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_nif' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_nif' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_address_1' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_address_1' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_address_2' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_address_2' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_postcode' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_postcode' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_city' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_city' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_state' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_state' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_country' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_country' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_phone' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_phone' ];
$new_fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_email' ] = $fields[ 'shipping' ]\[ 'fields' ]\[ 'shipping_email' ];

$new_fields = apply_filters( 'wcbcf_customer_meta_fields', $new_fields );

return $new_fields;
}
add_filter( 'woocommerce_customer_meta_fields', 'add_fields_to_user_admin' );

//We add the NIF to the billing and shipping address
function add_nif_field_to_user_billing_address( $fields, $user ) {
$fields[ 'nif' ] = get_user_meta( $user, 'billing_nif', true );

return $fields;
}
add_filter( 'woocommerce_user_column_billing_address', 'add_nif_field_to_user_billing_address', 1, 2 );

function add_nif_field_to_user_shipping_address( $fields, $user ) {
$fields[ 'nif' ] = get_user_meta( $user, 'shipping_nif', true );

return $fields;
}
add_filter( 'woocommerce_user_column_shipping_address', 'add_nif_field_to_user_shipping_address', 1, 2 );

//Adds the NIF field to Edit my address
function add_nif_field_to_edit_address( $fields, $user, $name ) {
$fields[ 'nif' ] = get_user_meta( $user, $name . '_nif', true );

//Sorts the fields
$new_fields[ 'first_name' ] = $fields[ 'first_name' ];
$new_fields[ 'last_name' ] = $fields[ 'last_name' ];
$new_fields[ 'company' ] = $fields[ 'company' ];
$new_fields[ 'nif' ] = $fields[ 'nif' ];
$new_fields[ 'address_1' ] = $fields[ 'address_1' ];
$new_fields[ 'address_2' ] = $fields[ 'address_2' ];
$new_fields[ 'postcode' ] = $fields[ 'postcode' ];
$new_fields[ 'city' ] = $fields[ 'city' ];
$new_fields[ 'state' ] = $fields[ 'state' ];
$new_fields[ 'country' ] = $fields[ 'country' ];

return $new_fields;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'add_nif_field_to_edit_address', 10, 3 );

//Adds the NIF field to Order details
function add_nif_field_to_order_edit_address( $fields ) {
$fields[ 'nif' ] = array(
'label' => __( 'CIF/NIF', 'woocommerce' ),
'show' => false
);

//Sorts the fields
$new_fields[ 'first_name' ] = $fields[ 'first_name' ];
$new_fields[ 'last_name' ] = $fields[ 'last_name' ];
$new_fields[ 'company' ] = $fields[ 'company' ];
$new_fields[ 'nif' ] = $fields[ 'nif' ];
$new_fields[ 'address_1' ] = $fields[ 'address_1' ];
$new_fields[ 'address_2' ] = $fields[ 'address_2' ];
$new_fields[ 'postcode' ] = $fields[ 'postcode' ];
$new_fields[ 'city' ] = $fields[ 'city' ];
$new_fields[ 'state' ] = $fields[ 'state' ];
$new_fields[ 'country' ] = $fields[ 'country' ];

return $new_fields;
}
add_filter( 'woocommerce_admin_billing_fields', 'add_nif_field_to_order_edit_address' );
add_filter( 'woocommerce_admin_shipping_fields', 'add_nif_field_to_order_edit_address' );

function load_order_edit_address_stylesheet() {
echo '

```
';
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'load_order_edit_address_stylesheet' );
Thanks to them we will add the NIF/CIF fields, as well as the telephone and email address in the shipping address. Lastly, the new NIF/CIF field has to be added to the addresses that appear in My Account -> Edit My Address.
Copy to clipboardSyntax Highlighter//Adds the NIF field to Edit my address
function add_nif_field_to_edit_address( $fields, $user, $name ) {
    $fields[ 'nif' ] = get_user_meta( $user, $name . '_nif', true );

    //Sorts the fields
    $new_fields[ 'first_name' ] = $fields[ 'first_name' ];
    $new_fields[ 'last_name' ] = $fields[ 'last_name' ];
    $new_fields[ 'company' ] = $fields[ 'company' ];
    $new_fields[ 'nif' ] = $fields[ 'nif' ];
    $new_fields[ 'address_1' ] = $fields[ 'address_1' ];
    $new_fields[ 'address_2' ] = $fields[ 'address_2' ];
    $new_fields[ 'city' ] = $fields[ 'city' ];
    $new_fields[ 'postcode' ] = $fields[ 'postcode' ];
    $new_fields[ 'state' ] = $fields[ 'state' ];
    $new_fields[ 'country' ] = $fields[ 'country' ];

    return $new_fields;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'add_nif_field_to_edit_address', 10, 3 );
So that you do not get into a muddle, we are going to give you the whole code together, which is the one you have to add to your functions.php file:
Copy to clipboardSyntax Highlighter//We fix the default address
function address_fields( $fields ) {
    $fields[ 'nif' ] = array(
        'label' => __( 'CIF/NIF', 'woocommerce' ),
        'placeholder' => _x( 'Enter the CIF/NIF', 'placeholder', 'woocommerce' ),
        'required' => false,
        'class' => array( 'form-row-last' ),
        'clear' => true,
    );

    $fields[ 'company' ][ 'class' ][ 0 ] = 'form-row-first';
    $fields[ 'city' ][ 'class' ][ 0 ] = 'form-row-first';
    $fields[ 'state' ][ 'class' ][ 0 ] = 'form-row-last update_totals_on_change';
    $fields[ 'postcode' ][ 'class' ][ 0 ] .= ' update_totals_on_change';

    //We reorder the fields
    $new_fields[ 'country' ] = $fields[ 'country' ];
    $new_fields[ 'first_name' ] = $fields[ 'first_name' ];
    $new_fields[ 'last_name' ] = $fields[ 'last_name' ];
    $new_fields[ 'company' ] = $fields[ 'company' ];
    $new_fields[ 'nif' ] = $fields[ 'nif' ];
    $new_fields[ 'address_1' ] = $fields[ 'address_1' ];
    $new_fields[ 'address_2' ] = $fields[ 'address_2' ];
    $new_fields[ 'postcode' ] = $fields[ 'postcode' ];
    $new_fields[ 'city' ] = $fields[ 'city' ];
    $new_fields[ 'state' ] = $fields[ 'state' ];
    if ( isset( $fields[ 'email' ] ) )$new_fields[ 'email' ] = $fields[ 'email' ];
    if ( isset( $fields[ 'phone' ] ) )$new_fields[ 'phone' ] = $fields[ 'phone' ];

    return $new_fields;
}
add_filter( 'woocommerce_default_address_fields', 'address_fields' );

//We add the NIF to the billing and shipping address
function add_nif_field_to_billing_address( $fields, $order ) {
    $fields[ 'nif' ] = $order->order_custom_fields[ '_billing_nif' ][ 0 ];

    return $fields;
}
add_filter( 'woocommerce_order_formatted_billing_address', 'add_nif_field_to_billing_address', 1, 2 );

function add_nif_field_to_shipping_address( $fields, $order ) {
    $fields[ 'nif' ] = $order->order_custom_fields[ '_shipping_nif' ][ 0 ];

    return $fields;
}
add_filter( 'woocommerce_order_formatted_shipping_address', 'add_nif_field_to_shipping_address', 1, 2 );

function billing_address_format( $fields, $argumentos ) {
    $fields[ '{nif}' ] = $argumentos[ 'nif' ];
    $fields[ '{nif_upper}' ] = strtoupper( $argumentos[ 'nif' ] );

    return $fields;
}
add_filter( 'woocommerce_formatted_address_replacements', 'billing_address_format', 1, 2 );

//We reorder the fields of the default address
function localisation_address_format( $fields ) {
    $fields[ 'default' ] = "{name}\n{company}\n{nif}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}";
    $fields[ 'ES' ] = "{name}\n{company}\n{nif}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}";

    return $fields;
}
add_filter( 'woocommerce_localisation_address_formats', 'localisation_address_format' );

//We fix the shipping form
function shipping_form( $fields ) {
    $fields[ 'shipping_email' ] = array(
        'label' => __( 'Email Address', 'woocommerce' ),
        'required' => false,
        'class' => array( 'form-row-first' ),
        'validate' => array( 'email' ),
    );
    $fields[ 'shipping_phone' ] = array(
        'label' => __( 'Phone', 'woocommerce' ),
        'required' => true,
        'class' => array( 'form-row-last' ),
        'clear' => true,
    );
    $fields[ 'shipping_postcode' ] = array(
        'label' => __( 'Postcode / Zip', 'woocommerce' ),
        'placeholder' => __( 'Postcode / Zip', 'woocommerce' ),
        'required' => true,
        'class' => array( 'form-row-wide', 'address-field' ),
        'clear' => true,
        'custom_attributes' => array(
            'autocomplete' => 'no'
        )
    );

    return $fields;
}
add_filter( 'woocommerce_shipping_fields', 'shipping_form' );

//We fix the billing form
function billing_form( $fields ) {
    $fields[ 'billing_postcode' ] = array(
        'label' => __( 'Postcode / Zip', 'woocommerce' ),
        'placeholder' => __( 'Postcode / Zip', 'woocommerce' ),
        'required' => true,
        'class' => array( 'form-row-wide', 'address-field' ),
        'clear' => true,
        'custom_attributes' => array(
            'autocomplete' => 'no'
        )
    );

    return $fields;
}
add_filter( 'woocommerce_billing_fields', 'billing_form' );

//Adds the CIF/NIF field to users
function add_fields_to_user_admin( $fields ) {
    $fields[ 'billing' ][ 'fields' ][ 'billing_nif' ] = array(
        'label' => __( 'CIF/NIF', 'woocommerce' ),
        'description' => ''
    );

    $fields[ 'shipping' ][ 'fields' ][ 'shipping_nif' ] = array(
        'label' => __( 'CIF/NIF', 'woocommerce' ),
        'description' => ''
    );
    $fields[ 'shipping' ][ 'fields' ][ 'shipping_email' ] = array(
        'label' => __( 'Email', 'woocommerce' ),
        'description' => ''
    );
    $fields[ 'shipping' ][ 'fields' ][ 'shipping_phone' ] = array(
        'label' => __( 'Telephone', 'woocommerce' ),
        'description' => ''
    );

    //We reorder the fields
    $new_fields[ 'billing' ][ 'title' ] = $fields[ 'billing' ][ 'title' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_first_name' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_first_name' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_last_name' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_last_name' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_company' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_company' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_nif' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_nif' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_address_1' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_address_1' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_address_2' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_address_2' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_postcode' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_postcode' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_city' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_city' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_state' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_state' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_country' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_country' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_phone' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_phone' ];
    $new_fields[ 'billing' ][ 'fields' ][ 'billing_email' ] = $fields[ 'billing' ][ 'fields' ][ 'billing_email' ];

    $new_fields[ 'shipping' ][ 'title' ] = $fields[ 'shipping' ][ 'title' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_first_name' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_first_name' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_last_name' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_last_name' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_company' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_company' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_nif' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_nif' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_address_1' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_address_1' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_address_2' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_address_2' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_postcode' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_postcode' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_city' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_city' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_state' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_state' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_country' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_country' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_phone' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_phone' ];
    $new_fields[ 'shipping' ][ 'fields' ][ 'shipping_email' ] = $fields[ 'shipping' ][ 'fields' ][ 'shipping_email' ];

    $new_fields = apply_filters( 'wcbcf_customer_meta_fields', $new_fields );

    return $new_fields;
}
add_filter( 'woocommerce_customer_meta_fields', 'add_fields_to_user_admin' );

//We add the NIF to the billing and shipping address
function add_nif_field_to_user_billing_address( $fields, $user ) {
    $fields[ 'nif' ] = get_user_meta( $user, 'billing_nif', true );

    return $fields;
}
add_filter( 'woocommerce_user_column_billing_address', 'add_nif_field_to_user_billing_address', 1, 2 );

function add_nif_field_to_user_shipping_address( $fields, $user ) {
    $fields[ 'nif' ] = get_user_meta( $user, 'shipping_nif', true );

    return $fields;
}
add_filter( 'woocommerce_user_column_shipping_address', 'add_nif_field_to_user_shipping_address', 1, 2 );

//Adds the NIF field to Edit my address
function add_nif_field_to_edit_address( $fields, $user, $name ) {
    $fields[ 'nif' ] = get_user_meta( $user, $name . '_nif', true );

    //Sorts the fields
    $new_fields[ 'first_name' ] = $fields[ 'first_name' ];
    $new_fields[ 'last_name' ] = $fields[ 'last_name' ];
    $new_fields[ 'company' ] = $fields[ 'company' ];
    $new_fields[ 'nif' ] = $fields[ 'nif' ];
    $new_fields[ 'address_1' ] = $fields[ 'address_1' ];
    $new_fields[ 'address_2' ] = $fields[ 'address_2' ];
    $new_fields[ 'postcode' ] = $fields[ 'postcode' ];
    $new_fields[ 'city' ] = $fields[ 'city' ];
    $new_fields[ 'state' ] = $fields[ 'state' ];
    $new_fields[ 'country' ] = $fields[ 'country' ];

    return $new_fields;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'add_nif_field_to_edit_address', 10, 3 );

//Adds the NIF field to Order details
function add_nif_field_to_order_edit_address( $fields ) {
    $fields[ 'nif' ] = array(
        'label' => __( 'CIF/NIF', 'woocommerce' ),
        'show' => false
    );

    //Sorts the fields
    $new_fields[ 'first_name' ] = $fields[ 'first_name' ];
    $new_fields[ 'last_name' ] = $fields[ 'last_name' ];
    $new_fields[ 'company' ] = $fields[ 'company' ];
    $new_fields[ 'nif' ] = $fields[ 'nif' ];
    $new_fields[ 'address_1' ] = $fields[ 'address_1' ];
    $new_fields[ 'address_2' ] = $fields[ 'address_2' ];
    $new_fields[ 'postcode' ] = $fields[ 'postcode' ];
    $new_fields[ 'city' ] = $fields[ 'city' ];
    $new_fields[ 'state' ] = $fields[ 'state' ];
    $new_fields[ 'country' ] = $fields[ 'country' ];

    return $new_fields;
}
add_filter( 'woocommerce_admin_billing_fields', 'add_nif_field_to_order_edit_address' );
add_filter( 'woocommerce_admin_shipping_fields', 'add_nif_field_to_order_edit_address' );

function load_order_edit_address_stylesheet() {
    echo '
```

';
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'load_order_edit_address_stylesheet' );
With this, everything is now finished, configured and working perfectly normally. If you want to see all this code in action, you can do so in the **Herves-Vida** online shop. We hope that, as always, you find this solution useful and that, in the event that you come across any kind of problem or error, you let us know, as well as your comments about this tutorial.

> Update: We have slightly modified the code to repair a couple of errors we have detected and to add the new fields to the addresses in Users and Edit My Address. We have also detected that some PHP errors and warnings were being caused in the online shop, so we have modified the code to prevent any kind of error or warning from appearing. We fixed a problem with the placeholder attribute of the Postcode / Zip field, we simplified the code even further and we added the new fields to the addresses in Order details. We also updated the screenshot. We force the order to update when the state or province and/or the postcode is changed, in order to provide a solution to a WooCommerce error detected by [Raquel](https://artprojectgroup.com/woocommerce-plugins/wc-apg-weight-shipping#comment-258).
