The case for mandatory house number in addresses
When using Google Address Autocomplete to autofill the address fields, some customers forget to check or add a house number to their addresses. This problem causes issues with delivering the customer's purchase as carriers might not be able to locate the correct address.
In order to fix this problem, the first thought would be to validate the "Street address" field and make sure that a part of it is a number.
Well, this could work for the majority of addresses but not all of them. It turns out that "house numbers" are not always straightforward.
Depending on the culture, the house number might come first or last when writing an address. Other times, the house number might be accompanied by non-digits characters such as letters and separators like `/`. Also, many addresses do not have a house number at all, and it would be impossible for those customers to enter their correct addresses.
For those reasons and more, the plugin Google Address Autocomplete
cannot force users to enter a house number in the "Street address" field by default.
Making the house number field mandatory
One way to solve the problem is to create a new "House number" field and make it mandatory, and then map the "house number" value from the Google Places API to the newly created field.
In this case, if a house number value is not returned from the address suggestions that field will be empty, and the customer will not be able to move forward until a value is entered. For addresses that do not have a house number, the customer can be instructed to enter a value such as `0` or `N/A` to indicate that.
2. Click the button to "+ Add field" to create a new field in the Billing Fields group.
3. In the Edit field screen, select the field "Type" as "Text".
4. Give it an ID in the "Name" field that such as `billing_house_number`. Please note that the field name ending should match on both the Billing and Shipping groups.
5. Set the field label that will be visible on the checkout page in the field "Label", for instance "House number".
6. Set the field classes to `form-row-last`, and if you are also using Fluid Checkout
on your website, add the class `form-row-one-third`. Classes need to be separated with a comma `,`.
7. Set the field as "Required" if it is not yet set.
8. Click the "Save & Close" button to save the new field.
9. Back to fields list in the Billing group, click to edit the `billing_address_1` field.
10. In the Edit field screen, change the field "Label" to "Street name".
11. Remove the field "Placeholder" text.
12. Set the field classes to `form-row-first`, and if you are also using Fluid Checkout on your website, add the class `form-row-two-thirds`. Classes need to be separated with a comma `,`.
13. Click the "Save & Close" button to save the new field.
14. Back to fields list in the Billing group, move the new `billing_house_number` field in between the fields `billing_address_1` and `billing_address_2`.
15. At the bottom of the page, click the button "Save changes" to save the new position for the "House number" field.
16. Repeat the process for the shipping address, adding the "House number" field in the Shipping group.
At this point, the address fields in your checkout page should look like this.
The checkout page should now have the new "House number" field added, however, the plugin Google Address Autocomplete does not know about it yet.
If you used a different field ID, you'll need to adjust it in the field mapping. Please note that field IDs in the mapping are used without the group prefixes `billing_` or `shipping_`.