WooCommerce: Add House Number Field @ Checkout

A Dutch fan told me in Holland they’re really strict about addresses 🙂 In particular, all Dutch billing/shipping addresses require the “House Number”.

This must be therefore placed on the checkout, AFTER & BESIDE the Address_1 field and made required. Also, it’s a good idea to make this show in the Admin Order, the thank you page and the notification Emails.

Add House Number in the WooCommerce Checkout
Add House Number in the WooCommerce Checkout

PHP Snippet: Add House Number @ WooCommerce Checkout Billing/Shipping


/**
 * @snippet       Add House Number to WooCommerce Checkout
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=20663
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_checkout_fields' , 'bbloomer_add_field_and_reorder_fields' );
 
function bbloomer_add_field_and_reorder_fields( $fields ) {
 
    // Add New Fields
      
    $fields['billing']['billing_houseno'] = array(
    'label'     => __('House Number', 'woocommerce'),
    'placeholder'   => _x('House Number', 'placeholder', 'woocommerce'),
    'priority' => 51,
    'required'  => true,
    'class'     => array('form-row-last'),
    'clear'     => true
     );
 
    $fields['shipping']['shipping_houseno'] = array(
    'label'     => __('House Number', 'woocommerce'),
    'placeholder'   => _x('House Number', 'placeholder', 'woocommerce'),
    'priority' => 51,
    'required'  => true,
    'class'     => array('form-row-last'),
    'clear'     => true
     );
 
    // Remove Address_2 Fields
 
    unset($fields['billing']['billing_address_2']);
    unset($fields['shipping']['shipping_address_2']);
 
    // Make Address_1 Fields Half Width
 
    $fields['billing']['billing_address_1']['class'] = array('form-row-first');
    $fields['shipping']['shipping_address_1']['class'] = array('form-row-first');      
    
    return $fields;
}

// ------------------------------------
// Add Billing House # to Address Fields

add_filter( 'woocommerce_order_formatted_billing_address' , 'bbloomer_default_billing_address_fields', 10, 2 );

function bbloomer_default_billing_address_fields( $fields, $order ) {
$fields['billing_houseno'] = get_post_meta( $order->get_id(), '_billing_houseno', true );
return $fields;
}

// ------------------------------------
// Add Shipping House # to Address Fields

add_filter( 'woocommerce_order_formatted_shipping_address' , 'bbloomer_default_shipping_address_fields', 10, 2 );

function bbloomer_default_shipping_address_fields( $fields, $order ) {
$fields['shipping_houseno'] = get_post_meta( $order->get_id(), '_shipping_houseno', true );
return $fields;
}

// ------------------------------------
// Create 'replacements' for new Address Fields

add_filter( 'woocommerce_formatted_address_replacements', 'add_new_replacement_fields',10,2 );

function add_new_replacement_fields( $replacements, $address ) {
$replacements['{billing_houseno}'] = isset($address['billing_houseno']) ? $address['billing_houseno'] : '';
$replacements['{shipping_houseno}'] = isset($address['shipping_houseno']) ? $address['shipping_houseno'] : '';
return $replacements;
}

// ------------------------------------
// Show Shipping & Billing House # for different countries

add_filter( 'woocommerce_localisation_address_formats', 'bbloomer_new_address_formats' );

function bbloomer_new_address_formats( $formats ) {
$formats['IE'] = "{name}\n{company}\n{address_1}\n{billing_houseno}\n{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}";
$formats['UK'] = "{name}\n{company}\n{address_1}\n{billing_houseno}\n{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}";
return $formats;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

83 thoughts on “WooCommerce: Add House Number Field @ Checkout

  1. Hi there. I worked out how to send the house number on to PayPal by use of another snippet.
    However, can you tell me if it is posible for you to enable the house number also to be dispalyed in the addresses in the “My Account” section? That seems to be the only place it does not appear 🙂

    Custom work I know – kindly pleaase let me know.

    1. Well done Dav, thank you. I emailed you my quote. Cheers!

      1. Hey, the snippet works great! Thank you!
        I also want to enable the new house number field in the “My Account” section. Could you also tell me how to do this?
        I have another question: How can I seperate the country IDs, when I want to have the same format for every country in

        $formats['DE']

        ?

        1. Hi Patrick, if you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi Rodolfo,

    The house number field appears in the check-out. But does not show in the e-mail and PDF attachment.
    Any idea how to solve this?

    Regards, Chris

    1. Hi Christian! What country is the customer from? You will need to define this for each country code:

      $formats['US'] = ....
    2. And if there are multiple countries? comma seperate them between the brackets? (with or without space?) or cope the code snippet and fill in a different country code all over?

      1. Great!

      2. What was the solution for this wildcard?? I really dont want to add all the countries in the world by hand..;-)

      3. I tried $formats[‘default’] = … but doesnt work..;-(

  3. there is a problem with your function “bbloomer_default_billing_address_fields”
    error says “id was called incorrectly. Order properties should not be accessed directly.”

    1. Thank you! Fixed 🙂

  4. In WooCommerce 3.5.4 each field is displayed in an order based on their ‘priority’ value.
    This simplifies the code considerably – the $newfields array is no longer needed, nor is the array_merge() call.
    You do need to add the ‘priority’ element to the $fields[‘billing’][‘billing_houseno’] and $fields[‘shipping’][‘billing_houseno’] arrays. I used:
    ‘priority’ => $fields[‘billing’][‘billing_address_1’] + 5, (and ‘priority’ => $fields[‘shipping’][‘shipping_address_1’] + 5,)
    to ensure that it was directly after the address_1 field.

    1. Awesome! Thank you Damien

  5. Hi Rodolfo,

    I am now using

    function bbloomer_new_address_formats( $formats ) {
    $formats['AT'] = "{name}\n{company}\n{address_1} {billing_houseno} {shipping_houseno}\n{address_2}\n{postcode} {city}\n{state} {country}";
    $formats['BE'] = "{name}\n{company}\n{address_1} {billing_houseno} {shipping_houseno}\n{address_2}\n{postcode} {city}\n{state} {country}";
    

    but I really want this to be the format for all countries. Should I put in a wildcard for that (*) or just remove the lines?

    1. Hey Marco, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  6. Hi Rodolfo! Thanks for your code, it (still) works great 🙂

    I noticed the House Number field doesn’t show in the account area (edit-address and edit-address/billing/ ). Is there a way to add the House Number there as well?

    1. Hello Fokke, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  7. Hi Rodolfo,
    I believe this is what I am looking for. Also noticed you revised the code recently.
    I am running WC 3.3.5 and I noticed that the House Number is not displayed in Order details on confirmation page, Order details in Admin and in the Email.
    I just copied and pasted your code but it seems not to work.
    Do I miss anything?

    1. Hey Arjan, thanks so much for your comment! Did you try adding something similar to the following for your own country code?

      $formats['UK'] = ...
      
  8. Hi,

    I’m using this snippet for more than a year now.
    All worked fine. If I ever needed to change the shipping or billing housenumber, I had to edit this entry directly in the database by a simple select:

    SELECT *
    FROM `wp_postmeta`
    WHERE `post_id` =3802
    LIMIT 0 , 30

    For some reason the entries in the database for new orders are gone. So I can’t update the housenumber anymore. I suspect it it related to WooCommerce 3.3.

    I tried to force it with this piece of code, but without any luck.

    add_post_meta( $order_id, ‘_billing_houseno’, sanitize_text_field( $_POST [‘billing_houseno’] ) );

    Any suggestions?

    Regards,

    1. Hey Roland, thanks so much for your comment! Can you not update the Billing/Shipping House number from the Order Edit page in the WooCommerce Admin?

  9. Hello Rodolfo,
    This snippet is exactly what I was looking for!

    Unfortunately, the house number appear ONLY in the Order Admin….
    *I used the snippet as it is. Without any plugins or other snippets that may interfere.

    Maybe it because the new version of Woocommerce? Can you please check it?

    1. Not sure Liran, the snippet might miss one line of code to show it elsewhere. This is custom work, sorry but I can’t help here via the blog comments. Thanks for your understanding 🙂

  10. Hello Rodolfo,

    Can you help formatting the phone number? For example: 0123456789 should be displayed as 0123 456 789 (or with dashes 0123-456-789)

    I found some php code, but not sure how to apply it to woocommerce (I am not a developer): https://stackoverflow.com/questions/5872096/function-to-add-dashes-to-us-phone-number-in-php

    Any help is much appreciated.

    1. Nicu, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  11. Thank You Rodolfo Melogli for this blog!

    The house number is not displayed in WooCommerce itself.

    What can I change?

    Regards,

    Martijn

    1. Hey Martijn, thanks for your comment! What do you mean it’s not “displayed in WooCommerce itself”? Can you help me understand? 🙂

    2. The house number is not displayed to customer data. And will not appear in the confirmation email. See URL (link) for an example.

      https://www.emhostingendesign.nl/wp-content/uploads/2017/07/no-house-number.png

      1. Thank you Martijn, I will add this to my to-revise list 🙂

    3. Love! Any idea when it succeeds? May also apply for payment. Would be very useful to me.

    4. It has already been successful. I have added the following:

      $formats[‘NL’] = “{name}\n{company}\n{address_1} {billing_houseno} {shipping_houseno}\n{state}\n{postcode} {city}\n{country}”;

  12. Hello, thank you for this wonderful snippet. My problem is, that on a second order from customer the house number doesnt get displayed. So if the customer clicks on buy now, he gets an error that house number is a required field and has to fill it again to proceed. Can you help me?

    1. Hey Andrej, thanks for your comment! Are you saying the field doesn’t save?

  13. Hi,

    Thanks for the great snippet!

    I got the house nr to show up in the order dashboard, but when i click on ‘edit shipping fields’ the house nr is gone. It should be merged within the Address 1 field. So it should say: “Streename 41” under Address 1.

    Now they are two separate fields and that way our shipping company doesn’t see the house nr.

    The format I used is:
    $formats[‘NL’] = “{name}\n{company}\n{address_1} {billing_houseno} {shipping_houseno}\n{state}\n{postcode}\n{city}\n{country}”;

    Didn’t do any other changes. Could you please help me out? Running WP 4.7.3

    1. Thank you Liz for your feedback. I will need to allocate time to recheck this snippet, as that is quite complex. Thank you!

  14. Hi Rodolfo,

    Thanks for all your tutorials,
    I have been hitting my head with this issue many days trying to solve it on my own before asking for help here but it seems impossible.

    Your code works but when going to the Order details page (of each order) on the dashboard then Haus number does not show anywhere and Adress 2 shows blank. We need this for the export since the system is connected to a another platform doing the deliveries.

    I found a way to show it “under” the details” with the following code:

      add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_billing_fields_display_admin_order_meta', 10, 1);
    
      function my_custom_billing_fields_display_admin_order_meta($order) {
    echo '<strong>' . __('Shipping House number') . ':</strong> ' . get_post_meta($order-&gt;id, '_shipping_houseno', true) . '';
    }
    

    But I would like to override the Adress 2 field or at least to show the house number field under the Adress 1 and 2 fields.

    I also managed to add the “field” on the wp-content/plugins/woocommerce/includes/admin/meta-boxes file class-wc-meta-box-order-data
    adding it after 1 and 2 in the following way

    'address_1' =&gt; array(
    				'label' =&gt; __( 'Address 1', 'woocommerce' ),
    				'show'  =&gt; false
    			),
    			'address_2' =&gt; array(
    				'label' =&gt; __( 'Address 2', 'woocommerce' ),
    				'show'  =&gt; false
    			),
    			'shipping_houseno' =&gt; array(
    				'label' =&gt; __( 'Shipping Hausnummer', 'woocommerce' ),
    				'show'  =&gt; false
    			),
    

    But the field is shown empty, so I’m lost on this. Any help will be appreciated

    1. Hey Valentina, thanks for your comment! Quick question: have you correctly setup the “woocommerce_localisation_address_formats” filter for your country/countries?

  15. Hello Rodolfo,

    Thank you very much for the tutorials and snippet. House Number works perfect.
    I have only one problem, I added a extra field called BTW-nummer. It appears on the checkout page and emails with the txt “{vatno}” also the field “country” is not showing anymore.

    Please, any tips to solve this?

    Thanks
    Ray

    /**
     * @snippet       Add House and Vat Number to WooCommerce Checkout
     * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
     * @sourcecode    https://businessbloomer.com/?p=20663
     * @author        Rodolfo Melogli
     * @testedwith    WooCommerce 2.6.4
     */
     
    add_filter( 'woocommerce_checkout_fields' , 'bbloomer_add_field_and_reorder_fields' );
     
    function bbloomer_add_field_and_reorder_fields( $fields ) {
     
        // Add New Fields
    
        $fields['billing']['billing_houseno'] = array(
        'label'     => __('Huisnummer', 'woocommerce'),
        'placeholder'   => _x('', 'placeholder', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-last'),
        'clear'     => true
         );
    
        $fields['billing']['billing_vatno'] = array(
        'label'     => __('BTW-nummer', 'woocommerce'),
        'placeholder'   => _x('', 'placeholder', 'woocommerce'),
        'required'  => false,
        'class'     => array('form-row-last'),
        'clear'     => true
         );
     
        $fields['shipping']['shipping_houseno'] = array(
        'label'     => __('Huisnummer', 'woocommerce'),
        'placeholder'   => _x('', 'placeholder', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-last'),
        'clear'     => true
         );
    
        // Remove Address_2 Fields
     
        unset($fields['billing']['billing_address_2']);
        unset($fields['shipping']['shipping_address_2']);
     
        // Make Address_1 Fields Half Width
     
        $fields['billing']['billing_company']['class'] = array('form-row-first');
        $fields['billing']['billing_address_1']['class'] = array('form-row-first');
        $fields['shipping']['shipping_address_1']['class'] = array('form-row-first');
     
        // Billing: Sort Fields
          
        $newfields['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
        $newfields['billing']['billing_last_name']  = $fields['billing']['billing_last_name'];
        $newfields['billing']['billing_company']    = $fields['billing']['billing_company'];
        $newfields['billing']['billing_vatno']      = $fields['billing']['billing_vatno'];
        $newfields['billing']['billing_email']      = $fields['billing']['billing_email'];
        $newfields['billing']['billing_phone']      = $fields['billing']['billing_phone'];
        $newfields['billing']['billing_country']    = $fields['billing']['billing_country'];
        $newfields['billing']['billing_address_1']  = $fields['billing']['billing_address_1'];  
        $newfields['billing']['billing_houseno']    = $fields['billing']['billing_houseno'];
        $newfields['billing']['billing_city']       = $fields['billing']['billing_city'];
        $newfields['billing']['billing_postcode']   = $fields['billing']['billing_postcode'];
        $newfields['billing']['billing_state']      = $fields['billing']['billing_state'];
       
        // Shipping: Sort Fields
          
        $newfields['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name'];
        $newfields['shipping']['shipping_last_name']  = $fields['shipping']['shipping_last_name'];
        $newfields['shipping']['shipping_company']    = $fields['shipping']['shipping_company'];
        $newfields['shipping']['shipping_country']    = $fields['shipping']['shipping_country'];
        $newfields['shipping']['shipping_address_1']  = $fields['shipping']['shipping_address_1'];  
        $newfields['shipping']['shipping_houseno']    = $fields['shipping']['shipping_houseno'];
        $newfields['shipping']['shipping_city']       = $fields['shipping']['shipping_city'];
        $newfields['shipping']['shipping_state']      = $fields['shipping']['shipping_state'];
        $newfields['shipping']['shipping_postcode']   = $fields['shipping']['shipping_postcode'];
     
        $checkout_fields = array_merge( $fields, $newfields);
        return $checkout_fields;
    }
     
    /* Removed 2016-10-19 at 13:52:13+00:00
     
    // ------------------------------------
    // Show house and vat number in the Order Admin
    
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'bbloomer_show_houseno_order_billing', 10, 1 );
     
    function bbloomer_show_houseno_order_billing($order){
        echo '<p><strong>'.__('House Number').':</strong> ' . get_post_meta( $order->id, '_billing_houseno', true ) . '</p>';
    }
    
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'bbloomer_show_vatno_order_billing', 10, 1 );
     
    function bbloomer_show_vatno_order_billing($order){
        echo '<p><strong>'.__('Vat Number').':</strong> ' . get_post_meta( $order->id, '_billing_vatno', true ) . '</p>';
    }
     
    add_action( 'woocommerce_admin_order_data_after_shipping_address', 'bbloomer_show_houseno_order_shipping', 10, 1 );
     
    function bbloomer_show_houseno_order_shipping($order){
        echo '<p><strong>'.__('House Number').':</strong> ' . get_post_meta( $order->id, '_shipping_houseno', true ) . '</p>';
    }
    
    */
     
     
     
    // ------------------------------------
    // Add Billing House # to Address Fields
     
    add_filter( 'woocommerce_order_formatted_billing_address' , 'bbloomer_default_billing_address_fields', 10, 2 );
     
    function bbloomer_default_billing_address_fields( $fields, $order ) {
    $fields['billing_houseno'] = get_post_meta( $order->id, '_billing_houseno', true );
    return $fields;
    }
     
    // Add Billing Vat # to Address Fields
     
    add_filter( 'woocommerce_order_formatted_billing_vatno' , 'bbloomer_default_billing_vatno_fields', 10, 2 );
     
    function bbloomer_default_billing_vatno_fields( $fields, $order ) {
    $fields['billing_vatno'] = get_post_meta( $order->id, '_billing_vatno', true );
    return $fields;
    }
     
    // ------------------------------------
    // Add Shipping House # to Address Fields
     
    add_filter( 'woocommerce_order_formatted_shipping_address' , 'bbloomer_default_shipping_address_fields', 10, 2 );
     
    function bbloomer_default_shipping_address_fields( $fields, $order ) {
    $fields['shipping_houseno'] = get_post_meta( $order->id, '_shipping_houseno', true );
    return $fields;
    }
     
     
     
    // ------------------------------------
    // Create 'replacements' for new Address Fields
     
    add_filter( 'woocommerce_formatted_address_replacements', 'add_new_replacement_fields',10,2 );
     
    function add_new_replacement_fields( $replacements, $address ) {
    $replacements['{billing_houseno}'] = isset($address['billing_houseno']) ? $address['billing_houseno'] : '';
    $replacements['{billing_vatno}'] = isset($address['billing_vatno']) ? $address['billing_vatno'] : '';
    $replacements['{shipping_houseno}'] = isset($address['shipping_houseno']) ? $address['shipping_houseno'] : '';
    return $replacements;
    }
     
     
     
    // ------------------------------------
    // Show Shipping & Billing House # for different countries
     
    add_filter( 'woocommerce_localisation_address_formats', 'bbloomer_new_address_formats' );
     
    function bbloomer_new_address_formats( $formats ) {
    $formats['NL'] = "{name}\n{company}\n{vatno}\n{address_1} {billing_houseno} {shipping_houseno}\n{postcode} {city}\n{state}\n{country}";
    $formats['IE'] = "{name}\n{company}\n{address_1}\n{billing_houseno}\n{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}";
    $formats['UK'] = "{name}\n{company}\n{address_1}\n{billing_houseno}\n{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}";
    return $formats;
    }
    
    1. Hey DutchRay, thanks for your comment.

      I only give support to official Business Bloomer Fans, but as a matter of fact check this line, the hook is not correct:

      add_filter( 'woocommerce_order_formatted_billing_vatno' , 'bbloomer_default_billing_vatno_fields', 10, 2 );
      

      Hope this helps!

      1. Hello Rodolfo,

        Appreciate your quick response, but I do not see the solution.

        Sorry. Thanks for your support so far.

        Ray

        1. Change woocommerce_order_formatted_billing_vatno with woocommerce_order_formatted_shipping_address 😉

  16. Thank you, the housenumber field has appeared! Do you know how I can make this new field appear in the REST API too? Do you know if it is possible?

    1. Excellent to hear that Wolter! I’m afraid I’m not familiar with the REST API, sorry 🙂

  17. How to add the Phone number to the shipping address field. I tried editing but i always ended up with a blank form screen 🙁

    1. Hey Santhosh thanks for your comment! I can’t offer free support here on the blog but adding phone number should be very easy – you just need to substitute all the “shipping_house_no” strings with “shipping_phone_no”. Hope this helps a little 🙂

      1. Thank You Rodolfo Melogli so much for this blog!
        I got the above snippet to work, But i ended in one major bug 🙁

        Cart total is not updating automatically after changing the zip code/ postcode. I know it has a class named “update_totals_on_change” but I can’t able to figure out where should I use that class.
        Waiting for your reply 🙂

        1. Thank You! I found the solution

          $fields[‘billing’][‘billing_postcode’][‘class’] = array(‘form-row-last’,’update_totals_on_change’);

          1. Awesome, thanks so much Santhosh!

  18. Thank you for providing this but could you add some more info.. Where do i need to put the code? In the theme function.php? I did that and it did nothing at all. Also do I need to change thing when i add it?

    1. Hey there, thanks very much for your feedback! Yes, indeed, you need to place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/

      And no, you won’t need to change much 🙂

  19. Hi Rodolfo,

    Been testing as promised, but I’m afraid I can’t get it to work correctly. See my screenshot: http://prntscr.com/cy05pr
    Screenie is a 3-in-1: on the right side is the front end, checkout page. Billing Fields are just perfect now, thank you very much for that, I love it!
    The house number is still a problem though: top left shows how the address is displayed on emails (both to customer and to me) and bottom left shows how the fields turn up in the order admin. Nowhere a sign of the house number field, unfortunately.

    I think I can follow most of your snippet’s logic, but was puzzled by the replacement fields – it didn’t appear to change anything whether I put them in my functions.php or not. (Put them in though!)

    On a sidenote: unsetting the default fields (address_2) didn’t work for me. Had to comment them out in the list where you define the order of the fields. That they still appear in my screenie is because I wanted to keep these fields in. 🙂

    And: I really appreciate it very, very much how much time and effort you put into this already! Thank you!

    1. Uhm – it worked on my development site, but not retroactively. I had to put a new order through. If this is not the case, then there is something else that is conflicting.

      Maybe try removing the “reorder” part completely, and instead of:

          $checkout_fields = array_merge( $fields, $newfields);
          return $checkout_fields;
      

      just use

          return fields;
      
      1. Hi Rodolfo,
        thank you so much for trying to fix this stubborn problem!

        I had tried with new orders, but did again as you suggested. After that I tried your second suggestion by replacing the code, but that just removed all the fields from the checkout completely 🙂 Then I even tried with another theme (Twenty-sixteen), but same result.
        Which means that I’m going to give up really. Enough time spent on it! I’ll just have to keep my fingers crossed that people will add their house numbers to the address field ^^.

        Your snippet still helped me enormously though! With it, I’ve managed to change the layout to exactly how I wanted it to be. And as a sweet side-effect, unsetting default fields did something after all: it removed the old fields. Then they were replaced by the ones in the list. In my case it meant that a field that wasn’t defined correctly by the theme I use, got replaced by a perfectly working field now 🙂

        All in all, can’t thank you enough for all your effort and help! Looking forward to your new tutorial, learning lots there! ^^

        1. Ok, pity! Thank you for your comment 🙂

  20. Hi Rodolfo,

    Great article and code snippets. Just what I was looking for for my client.

    I have the same issue as Henriette has. The housenumber doesn’t show up on the emails. As Henriette, I want them to be placed just after the street-name (address_1).

    Your provided snippet works, but as a seperate field, not just after the street-address.

    Do you have a solution for this?

    1. Yes Roland, I just published a revised version of the blog! Let me know 🙂

      1. Hi Rodolfo,

        Thanks a million!
        Made a small customization to your code, so the address and housenummer are on the same line (removed some \n):

        // ————————————
        // Show Shipping & Billing House # for different countries

        add_filter( ‘woocommerce_localisation_address_formats’, ‘webinweb_new_address_formats’ );

        function webinweb_new_address_formats( $formats ) {
        $formats[‘NL’] = “{name}\n{company}\n{address_1} {billing_houseno}{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}”;
        $formats[‘BE’] = “{name}\n{company}\n{address_1} {billing_houseno}{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}”;
        $formats[‘DE’] = “{name}\n{company}\n{address_1} {billing_houseno}{shipping_houseno}\n{city}\n{state}\n{postcode}\n{country}”;
        return $formats;
        }

        1. AWESOME! Thanks Roland 🙂

  21. Hi Rodolfo,

    There is this odd problem in the admin panel I come across and which I just can’t figure out.

    For me, the house number does not show up in the order overview, nor in emails.
    However, it does show up if you add a new order from the dashboard (button at the top of the order overview page). This triggers a new screen, similar to the checkout page. Interestingly, these fields are still organised in the default layout (they don’t follow the code in this snippet) and here the house number is added at the far bottom.

    The extra snippet for emails doesn’t work for me either.

    It would be nice to get this dashboard order form in the same layout as the frontend order form, but for me it’s much more important to have the house number show up in the right place too: in the order overview and emails. Now it looks as if they’re called upon in the wrong part of the dashboard.

    Is there a chance you could point me in the right direction to solve this problem? 🙂

    Best regards,
    Henriët

    1. Hi Rodolfo,

      Just noticed (blush!) that the housenumber does show up in the order admin, just not in the overview that’s presented first, but when you click the order number for the details. That’s perfect for me! 🙂

      However, still have problems with the emails.
      Here the house number doesn’t show up next to the street name in the billing address, but as a “loose remark” above the customer data, displaying it for both shipping & billing, even if the shipping fields weren’t used.

      Any tips to solve this would be highly appreciated ^^.

      1. Henriët, thanks for your comments! Can you send me a screenshot to show me what happens on the emails? Thanks a lot 🙂

        1. Thank you very much, Rodolfo! 🙂
          I didn’t see where I could add a screenshot here, so I’ve replied in the confirmation mail that you sent me. Hope that’s ok!

          1. Hey Henriët, as promised I published a new version of the blog which should address this problem. Let me know!

            1. Hi Rodolfo!
              This is wonderful!
              Never got a reply in the mail, just chanced to see it here. Will do some testing, probably this weekend and will let you know how that went:)

  22. Very good!

    I’m testing the code, I am trying to validate fields that I am creating, using hook add_action(‘woocommerce_checkout_process’, ‘validate’).

    within that validate function, I try to catch the field created using $ _POST.

    More’m not getting, you know what I’m doing wrong?

    1. Hello De Silveira, thanks for your comment! That field should validate automatically, as we added ‘required’ => true in the field options. Let me know!

  23. Hello Rodolfo,

    First of all thank you very, very much for all the tutorials and snippets 🙂 I’ve learnt a lot from you! Not only by just copy/pasting these, but I’ve been playing around with some things as well as you’ve suggested, and found to my surprise that I could actually add some working code 😀

    The coding above was most welcome too, and I’ve customised it a bit myself, so I had the perfect fields for my site.
    However – it appeared that exactly this snippet/piece of code proved to cause an error. I was afraid it was in my own customisation, so I removed those, and when that didn’t help I removed the whole (edited) snippet thinking I must’ve missed something and replaced it with the exact code you’ve wrote out above. To my surprise, the error still turned up.

    What’s the problem then? Just below the shipping fields, but still in that column, there is a small checkbox for creating a new account (if you’ve activated that in the Woo settings and are not logged in yourself). By ticking it, one or two new fields should appear (username if you’ve not set that to being email, and a password field).
    After adding your above code to my functions.php, the checkbox is displayed and can be ticked, however, the fields for username and password do not show up anymore, no matter what.
    I’ve checked and doublechecked, but this is the code that causes this – not anything else. It was not in the reordering of the fields, nor in my own customisations. Before adding your code they’re there, after they’re not.

    Could it be that as you’ve replaced/removed all the original fields with “newfields”, that somehow some original code went missing from that column, causing this problem? As I’m really just a lay(wo)man in php, this is just a wild guess, mind 😀

    The checkbox and connected fields are a bit sneaky anyway as you must be logged out to have them displayed at all (just like the message at the top for returning customers). Hope you can help with this, as I’d love to use your code for rearranging/editing these fields here!

    Kind regards,
    Henriët

    1. Henriët, thank you so much for your comment. Spot on – you actually found a bug 🙂

      I edited the snippet now, and in particular I added these 2 new lines at the end:

      $checkout_fields = array_merge( $fields, $newfields);
      return $checkout_fields;
      

      In this way, the fields returned are the new ones PLUS the old ones (which should include the account fields).

      Let me know if this works for you!

      1. Hi Rodolfo!

        Thank you for your quick reply 🙂
        I’m very glad it was a real bug, and not my tinkering with the code 😀 and I’m even more glad that you found a solution for it. Been testing it on my test-site first, and so far it looks as if everything goes right now, makes me very happy!

        Coming across another silly thing now though, and that’s my username showing up in the postcode field… Can’t imagine that’s caused by this though, I’ve been reorganising my functions.php & style.css yesterday and something must have gone wrong there.
        Will have some more testing and searching to do next week then ^^.

        Anyway, thanks again for the solution 😀
        Had the perfect layout based on your snippet, and now I can use it once more and won’t have to start all over there – that is, after I iron out that other thingie, haha.

        Kind regards,
        ~Henriët

        1. Last comment 🙂
          found the cause of the other bug too, it was in upgrading to WordPress 4.6. Downgraded to 4.5.3 and all is fine again.
          Guess I should wait a little longer before upgrading and wait till all the new update bugs are caught, haha 🙂
          ~Henriet

          1. Brilliant, glad everything worked out! Keep in touch 🙂

  24. Cool stuff, was going to use a plugin to accomplish this, but this great snippet does the job beautifully!

    1. Excellent Conrad, glad this helped!

  25. Nice!
    I have only problem, that I don’t see that number in my order overview email etc.

    1. Thanks for your comment Michael! Try with this (untested) and let me know:

      
      add_filter('woocommerce_email_order_meta_keys', 'bbloomer_add_house_no_to_emails');
      
      function bbloomer_add_house_no_to_emails( $keys ) {
           $keys['Billing House Number'] = '_billing_houseno';
           $keys['Shipping House Number'] = '_shipping_houseno'; 
           return $keys;
      }
      
      
    2. Hello Michael, have you solved the problem with the emails. I’m searching like mad for a solution. Thanks!

      1. Hey Razvan, what problem are you having with emails? The latest revision I made to this snippet automatically adds the field to emails as well 🙂

  26. Thanks. This is indeed correct. That should be there in WC by default.

    1. Thanks for your feedback Jake 🙂

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.