In this article we will explore the necessary requirements to create a custom address attribute which will be used in customer addresses. The creation of these is very similar to how you would create a simple customer attribute. You can read further on that here - how to create a customer attribute.
There are only a few things we need to know before starting. All customer addresses have the same attribute sets - this means that the field you add will show in both shipping and billing addresses by default. We will look into how you can work around this in future articles.
As always we will create a data patch to create our attribute.
The same as for regular customer attributes we are using CustomerSetupFactory to instantiate the setup class
One caveat for address specific fields is that in addAttribute function we need to pass in customer_address. This is required so that attribute would be added in the correct area.
In addition we are adding attribute set and attribute group id which we get from customer_address entity.
A very important part here is to set the used_in_forms.
In the following articles we will show you how to include this field in checkout shipping and billing addresses, how to validate and save it.