Skip to main content
shoppy.customer.addresses()
Get and manage customer shipping addresses.

Get All Addresses

const addresses = await shoppy.customer.addresses()
Returns Promise<ShopifyCustomerAddress[]>

Add Address

shoppy.customer.addAddress(address)
ParamTypeDescription
addressAddressInputAddress details
Returns Promise<ShopifyCustomerAddress>

Update Address

shoppy.customer.updateAddress(addressId, address)
ParamTypeDescription
addressIdstringAddress ID to update
addressAddressInputNew address details
Returns Promise<ShopifyCustomerAddress>

Delete Address

shoppy.customer.deleteAddress(addressId)
Returns Promise<void>

Set Default Address

shoppy.customer.setDefaultAddress(addressId)
Returns Promise<ShopifyCustomer>

AddressInput

FieldTypeDescription
address1stringStreet address
address2stringApt, suite, etc.
citystringCity
companystringCompany name
countrystringCountry
firstNamestringFirst name
lastNamestringLast name
phonestringPhone number
provincestringState/Province
zipstringPostal code

Examples

Display addresses

const addresses = await shoppy.customer.addresses()

addresses.forEach(addr => {
    console.log(addr.formatted.join('\n'))
})

Add new address

const newAddress = await shoppy.customer.addAddress({
    firstName: 'John',
    lastName: 'Doe',
    address1: '123 Main St',
    city: 'New York',
    province: 'NY',
    zip: '10001',
    country: 'United States'
})

console.log(`Added address: ${newAddress.id}`)

Address form handler

document.querySelector('#address-form').addEventListener('submit', async (e) => {
    e.preventDefault()
    const formData = new FormData(e.target)

    const addressId = formData.get('addressId')
    const address = {
        firstName: formData.get('firstName'),
        lastName: formData.get('lastName'),
        address1: formData.get('address1'),
        address2: formData.get('address2'),
        city: formData.get('city'),
        province: formData.get('province'),
        zip: formData.get('zip'),
        country: formData.get('country'),
        phone: formData.get('phone')
    }

    if (addressId) {
        await shoppy.customer.updateAddress(addressId, address)
    } else {
        await shoppy.customer.addAddress(address)
    }

    showSuccess('Address saved!')
})

Set default address

async function makeDefault(addressId) {
    await shoppy.customer.setDefaultAddress(addressId)
    showToast('Default address updated')
}

Delete address

async function removeAddress(addressId) {
    if (confirm('Delete this address?')) {
        await shoppy.customer.deleteAddress(addressId)
        refreshAddressList()
    }
}