Skip to main content

Overview

An address is where something goes or who gets billed. Every cart collects a shipping and a billing address, and signed-in customers can keep an address book. Addresses matter beyond the label on a parcel: the shipping address decides which delivery options a customer sees and how much tax they pay.

Address fields

Countries and states are named by their ISO codes — country_code: "US", state_code: "CA" — never by an ID. A code means the same thing everywhere, so you can send one without looking anything up first.The older names country_iso and state_abbr still work but are going away. Use country_code and state_code in new code.

Address forms that adapt

Address formats are not universal. The United States wants a state and a ZIP code; Hong Kong wants neither. A form that demands both everywhere will block real customers from checking out. Every country tells you what it needs:
Drive the form from those two flags rather than hardcoding a list of countries. When states_required is false, let the customer type a state_name instead of picking a state_code. Only countries you actually sell to are listed — that’s decided by your Markets.

The customer address book

A signed-in customer can save addresses and mark defaults, so checkout is one tap next time.

Addresses at checkout

On a cart you can point at a saved address or send a new one inline:
Setting the shipping address is what makes delivery options and tax appear, so do it before asking the customer to choose delivery. The updated cart comes back with new totals — you don’t need a second request.
An address is copied onto the order when the cart completes, not linked to. Editing a saved address next year does not rewrite last year’s invoice — which is exactly what you want when a customer moves house.

Validating addresses

Spree checks that required fields are present and that the state and postal code make sense for the country. Anything it rejects comes back as a 422 naming the field, so you can put the message next to the input. For real-world verification — that a street exists, that a unit number is missing — connect an address validation service. See Providers.

How geography flows through a purchase

1

A customer arrives

Their country resolves to a Market, which sets the currency and locale, and whether prices are shown with tax included.
2

They fill in an address

The form adapts to the country using states_required and zipcode_required.
3

Delivery options appear

The shipping address decides which delivery methods can reach them, and what each costs.
4

Tax is worked out

The same address decides the tax charged.
5

The order is placed

Both addresses are copied onto the order as a permanent record.
  • Markets — where you sell, in which currency
  • Fulfillments — how the address shapes delivery options
  • Taxes — how the address shapes tax
  • Carts — the checkout flow end to end