Convert additional address fields
Merchants can enable additional address fields for shipping and billing addresses at checkout to comply with localization requirements in specific regions.
This guide introduces how to convert between the standard and extended address formats when additional address fields have been enabled by a merchant. Example extensions are provided for converting and updating extended address fields.
How it works
Anchor link to section titled "How it works"When additional address fields are enabled, supported countries will offer an extended address form in checkout. The extended address format is a modification of the standard address form. The extended address form and additional field definitions are configured per country in the public GitHub repository worldwide. Each country has its own YAML which defines the following:
format_extended.edit
: The extended address form as displayed in checkout. -additional_address_fields
: Denotes the supported additional fields and whether a field is required.combined_address_format
: Details the strategy used to concatenate the additional fields back into the standard address fields. This includes country-specific decorators so the address is displayed to customers in a common localized format.
For example, BR.yml.
When the address is saved from checkout, the data entered in the additional fields is merged into the relevant standard fields:
streetName
andstreetNumber
are saved inaddress1
Line2
andneighborhood
are saved inaddress2
Upon concatenation, address data is clearly delineated with a reserved character, and enhanced with regional decorators. This formatting ensures that API clients are able to reliably split the data back into the additional fields, and that the combined data is displayed appropriately in the frontend.
Shopify uses the JavaScript and Ruby libraries offered in Worldwide to concatenate and split the data stored in the additional fields. We recommend that you use the same libraries in your app to ensure a consistent experience.
JavaScript clients
Anchor link to section titled "JavaScript clients"Worldwide offers the parsing logic as an npm
package @shopify/worldwide.
The npm
package provides concatenation and splitting functions for both address1
and address2
:
concatenateAddress1
concatenateAddress2
splitAddress1
splitAddress2
The usage details are described in the README.
Ruby clients
Anchor link to section titled "Ruby clients"Worldwide offers the ruby class, Worldwide::Address
, which exposes the following public methods:
concatenate_address1
concatenate_address2
split_address1
split_address2
The usage details are described in the README.
These methods are used to concatenate additional address fields back with the standard fields. They can also be used to split the additional address fields from the standard fields, address1
and address2
.
Requirements
Anchor link to section titled "Requirements"- The additional address fields feature is enabled on the store.
- You've created a Partner account.
- You've created a development store.
You've created an app that uses Shopify CLI 3.49.5 or higher. If you previously installed Shopify CLI, then make sure that you're using the latest version.
If you plan to create a UI for your extension, then start with the Remix app template.
You've installed Node.js 16 or higher.
You've installed your app on the development store.
Rust-specific requirements
Anchor link to section titled "Rust-specific requirements"The following requirements are specific to Rust-based development with Shopify Functions.
You've installed Rust.
On Windows, Rust requires the Microsoft C++ Build Tools. Make sure to select the Desktop development with C++ workload when installing the tools.
You've installed cargo-wasi:
Example: Performing address validations on the extended address form
Anchor link to section titled "Example: Performing address validations on the extended address form"The following example checkout UI extension uses splitAddress
and the Cart and Checkout Validation API to block checkout and render an error message when the street number and neighborhood in Brazil do not meet defined conditions:
Example: Updating addresses when additional address fields are enabled
Anchor link to section titled "Example: Updating addresses when additional address fields are enabled"The following example checkout UI extension uses concatenatedAddress
and useApplyShippingAddressChange
to convert the extended address fields into the standard address fields and updates the standard address fields address1
and address2
: