Bootstrap Achilles

search box

Woocommerce checkout house number verification

Here is how I make sure users don't forget to enter the house number of the street in the billing/shipping address.


Introduction

Navigate to /wp-content/themes/flatsome-child/functions.php in your theme.

PHP

            add_action('woocommerce_checkout_process', 'address_field_validation', 10, 0);
            function address_field_validation() {
            
            // The field value to check
            $post_value = $_POST['billing_address_1'];
            
            // If there is no number in this field value, stops the checkout process
            // and displays an error message.
            if ( $post_value && ! preg_match( '/[0-9]+/', $post_value ) ) {
                // The error message
                throw new Exception( sprintf( __( 'there is no house number in the feild', 'woocommerce' ) ) );
            }
            }