Update cart metafields
This guide shows you how to use a cart handler to update cart metafields.
RequirementsAnchor link to section titled "Requirements"
Step 1: Read cart metafieldsAnchor link to section titled "Step 1: Read cart metafields"
Update the cart query fragment to return cart metafields. For more information, refer to the default
The following example adds the
Step 2: Create a metafield formAnchor link to section titled "Step 2: Create a metafield form"
useFetcher hook to create a form that submits information that you want to store in a metafield. The hook submits a form request to the
/cart route's action when users submit with this metafield form. You can use this component anywhere in the app.
When you use
fetcher.submit, make sure there's a data key with the name
CartForm.INPUT_NAME. The key value must be a JSON stringified object with
Step 3: Handle the update metafield form requestAnchor link to section titled "Step 3: Handle the update metafield form request"
Handle the update metafield form request in an
action. Use the
cart, created from
createCartHandler, to handle cart mutation requests to the Storefront API.
- Learn how to update buyer identity.