# Require a House Number in the Street Address

> Catches addresses typed without a house or building number, one of the most common reasons parcels come back undelivered.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, checkout, validation, address
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-require-house-number/

## Code

```php
$wpide_house_number_skip = array( 'IE' ); // Countries to skip.

add_action( 'woocommerce_after_checkout_validation', function ( $data, $errors ) use ( $wpide_house_number_skip ) {
    if ( empty( WC()->cart ) || ! WC()->cart->needs_shipping() ) {
        return;
    }

    $prefix  = ! empty( $data['ship_to_different_address'] ) ? 'shipping_' : 'billing_';
    $country = (string) ( $data[ $prefix . 'country' ] ?? '' );
    $line    = trim( (string) ( $data[ $prefix . 'address_1' ] ?? '' ) . ' ' . (string) ( $data[ $prefix . 'address_2' ] ?? '' ) );

    if ( '' !== $line && ! in_array( $country, $wpide_house_number_skip, true ) && ! preg_match( '/\d/', $line ) ) {
        $errors->add( 'validation', 'Please include your house or building number in the street address.' );
    }
}, 10, 2 );
```

## Notes

Only orders that need shipping are checked; add countries where addresses often have no numbers to $wpide_house_number_skip.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a House Number in the Street Address" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
