useCartAddAttributes

A cart hook that helps you easily add / append cart-level custom attributes to existing custom attributes.

// import
import { useCartAddAttributes } from '@backpackjs/storefront';

// instantiation
const { cartAddAttributes, ...addAttributesStatus } = useCartAddAttributes();

// use
const cartAttributesToAdd = [
  { key: "customerType", value: "VIP" },
  { key: "withGiftWrap", value: "true" }
]

const customAttributes = await cartAddAttributes({
  customAttributes: cartAttributesToAdd
})

customAttributes

cart custom attributes array [ { key: 'attrKey', value: 'attrValue' }, ... ]

For line_item custom attributes see useCartAddItems, or useCartUpdateItems

Last updated