Adding multiple custom metafields to the Cart

Topic summary

A developer is encountering issues when attempting to add multiple custom metafields to a Shopify Hydrogen cart.

Current behavior:

  • When setting both dealer_id and store_name metafields, only dealer_id appears in the cart’s metafields array
  • When attempting to set only store_name (without dealer_id), no metafields appear at all
  • The developer has confirmed that store_name contains a valid, non-empty value

Technical context:
The implementation uses CartForm.ACTIONS.MetafieldsSet with a metafields array containing objects with namespace “custom” and keys “dealer_id” and “store_name”. The code appears to be using Shopify’s Cart API with a fetcher submission method.

Status: The issue remains unresolved with no responses or solutions provided yet.

Summarized with AI on November 14. AI used: claude-sonnet-4-5-20250929.

I’m trying add a few metafields to the Cart in Hydrogen using the code below. When I view the cart and log out the contents, only dealer_id shows up in the metafields array. If I try to only show store_name and ignore setting dealer_id, I actually end up with no metafields in the Cart object. I can also confirm that store_name is not empty.

fetcher.submit(
  {
    [CartForm.INPUT_NAME]: JSON.stringify({
      action: CartForm.ACTIONS.MetafieldsSet,
      inputs: {
        metafields: [
          {
            key: 'custom.dealer_id',
            type: 'string',
            value: store_vendor_id,
          },
          {
            key: 'custom.store_name',
            type: 'string',
            value: store_name,
          },
         
        ],
      },
    }),
  },
  {method: 'POST', action: '/cart'},
);
fragment CartApiQuery on Cart {
  metafields(identifiers:
  [
    {namespace: "custom", key: "dealer_id"},
    {namespace: "custom", key: "store_name"}
  ]) {
      key
      value
  }
  ...