Shopify / ui-extensions

MIT License
268 stars 35 forks source link

A useBillingAddress() hook #943

Closed nelson-maze closed 1 year ago

nelson-maze commented 1 year ago

Please list the related package(s)

checkout-ui-extensions

If this related to specific APIs or components, please list them here

A (proposed) useBillingAddress() hook

Is your feature request related to a problem? Please describe.

Digital products/products that do not require shipping are not impacted by the Shipping and Delivery settings in the Shopify Admin. Merchants that want to restrict the fulfillment of these types of products to a specific country set are unable to do so with Checkout UI Extensions because there is no access to the Billing Address at checkout. The useShippingAddress() hook remains null/empty throughout the entire checkout journey for users that have a cart comprised solely of digital/non-shippable products.

The basic functionality of a client-side cart validation extension we were looking to build was:

Since the shipping step of checkout is skipped, there is no real way to validate a user's billing address for geofencing orders.

The absence of this hook results in an awful post-order refund process that could have been avoided with a hook for Billing Address info to use in validating a cart/checkout. This was previously implemented with a simple JavaScript manipulation of the country selector in checkout.liquid and proved to be very effective in blocking customers from non-accepted regions. (i.e. delete all other countries from the select element)

Describe the changes you are looking for

A useBillingAddress() hook that provides the exact same functionality as useShippingAddress().

Describe alternatives you’ve considered

We've attempted to use useShippingAddress() - but this is ineffective when used in context with digital/non-shippable products. It remains null/empty throughout the entire checkout journey for digital products orders.

Additional context

dnagoda commented 1 year ago

Thanks for the detailed write up, @nelson-maze. I've added the request to our internal boards for review.

jarthorn commented 1 year ago

This has been shipped! 🎉

https://shopify.dev/docs/api/checkout-ui-extensions/unstable/react-hooks/buyer-identity/usebillingaddress