--- title: cartMetafieldDeleteDefault description: >- Creates a function that accepts a string key and removes the matching metafield from the cart. api_version: 2024-01 api_name: hydrogen source_url: html: >- https://shopify.dev/docs/api/hydrogen/2024-01/utilities/cartmetafielddeletedefault md: >- https://shopify.dev/docs/api/hydrogen/2024-01/utilities/cartmetafielddeletedefault.md --- # cart​Metafield​Delete​Default Creates a function that accepts a string key and removes the matching metafield from the cart. ## cart​Metafield​Delete​Default(**[options](#cartmetafielddeletedefault-propertydetail-options)**​) ### Parameters * **options** **CartQueryOptions** **required** ### Returns * **CartMetafieldDeleteFunction** ### ### CartMetafieldDeleteFunction * **export type CartMetafieldDeleteFunction = ( key: Scalars['String']['input'], optionalParams?: CartOptionalInput, ) => Promise;** ### CartQueryOptions * storefront The storefront client instance created by \[\`createStorefrontClient\`]\(docs/api/hydrogen/latest/utilities/createstorefrontclient). ```ts Storefront ``` * getCartId A function that returns the cart ID. ```ts () => string ``` * cartFragment The cart fragment to override the one used in this query. ```ts string ``` ### Storefront Interface to interact with the Storefront API. * query ```ts (query: RawGqlString, ...options: IsOptionalVariables> extends true ? [(StorefrontCommonExtraParams & Pick & ClientVariables>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontQueries[RawGqlString]["variables"] as Filter>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }, Record<"variables", RawGqlString extends never ? { [KeyType in keyof ({ [KeyType in keyof StorefrontQueries[RawGqlString]["variables"] as Filter>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontQueries[RawGqlString]["variables"] as Filter>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }>>)?] : [StorefrontCommonExtraParams & Pick & ClientVariables>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontQueries[RawGqlString]["variables"] as Filter>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }, Record<"variables", RawGqlString extends never ? { [KeyType in keyof ({ [KeyType in keyof StorefrontQueries[RawGqlString]["variables"] as Filter>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontQueries[RawGqlString]["variables"] as Filter>]: StorefrontQueries[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }>>]) => Promise & StorefrontError> ``` * mutate ```ts (mutation: RawGqlString, ...options: IsOptionalVariables> extends true ? [(StorefrontCommonExtraParams & ClientVariables>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontMutations[RawGqlString]["variables"] as Filter>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }, Record<"variables", RawGqlString extends never ? { [KeyType in keyof ({ [KeyType in keyof StorefrontMutations[RawGqlString]["variables"] as Filter>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontMutations[RawGqlString]["variables"] as Filter>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }>>)?] : [StorefrontCommonExtraParams & ClientVariables>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontMutations[RawGqlString]["variables"] as Filter>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }, Record<"variables", RawGqlString extends never ? { [KeyType in keyof ({ [KeyType in keyof StorefrontMutations[RawGqlString]["variables"] as Filter>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)]: ({ [KeyType in keyof StorefrontMutations[RawGqlString]["variables"] as Filter>]: StorefrontMutations[RawGqlString]["variables"][KeyType]; } & Partial>>)[KeyType]; } : { readonly [variable: string]: unknown; }>>]) => Promise & StorefrontError> ``` * cache ```ts Cache ``` * CacheNone ```ts () => NoStoreStrategy ``` * CacheLong ```ts (overrideOptions?: AllCacheOptions) => AllCacheOptions ``` * CacheShort ```ts (overrideOptions?: AllCacheOptions) => AllCacheOptions ``` * CacheCustom ```ts (overrideOptions: AllCacheOptions) => AllCacheOptions ``` * generateCacheControlHeader ```ts (cacheOptions: AllCacheOptions) => string ``` * getPublicTokenHeaders ```ts (props?: Partial> & Pick) => Record ``` * getPrivateTokenHeaders ```ts (props?: Partial> & Pick & { buyerIp?: string; }) => Record ``` * getShopifyDomain ```ts (props?: Partial>) => string ``` * getApiUrl ```ts (props?: Partial>) => string ``` * isApiError ```ts (error: any) => boolean ``` * i18n ```ts TI18n ``` ### StorefrontQueries Maps all the queries found in the project to variables and return types. ### AutoAddedVariableNames ```ts 'country' | 'language' ``` ### StorefrontCommonExtraParams * headers ```ts HeadersInit ``` * storefrontApiVersion ```ts string ``` * displayName ```ts string ``` ### StorefrontQueryOptions ```ts StorefrontCommonExtraParams & { query: string; mutation?: never; cache?: CachingStrategy; } ``` ### CachingStrategy Use the \`CachingStrategy\` to define a custom caching mechanism for your data. Or use one of the pre-defined caching strategies: CacheNone, CacheShort, CacheLong. * mode The caching mode, generally \`public\`, \`private\`, or \`no-store\`. ```ts string ``` * maxAge The maximum amount of time in seconds that a resource will be considered fresh. See \`max-age\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#:\~:text=Response%20Directives-,max%2Dage,-The%20max%2Dage). ```ts number ``` * staleWhileRevalidate Indicate that the cache should serve the stale response in the background while revalidating the cache. See \`stale-while-revalidate\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate). ```ts number ``` * sMaxAge Similar to \`maxAge\` but specific to shared caches. See \`s-maxage\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-maxage). ```ts number ``` * staleIfError Indicate that the cache should serve the stale response if an error occurs while revalidating the cache. See \`stale-if-error\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error). ```ts number ``` ### StorefrontError * errors ```ts StorefrontApiErrors ``` ### StorefrontApiErrors ```ts JsonGraphQLError[] | undefined ``` ### StorefrontMutations Maps all the mutations found in the project to variables and return types. ### NoStoreStrategy * mode ```ts string ``` ### AllCacheOptions Override options for a cache strategy. * mode The caching mode, generally \`public\`, \`private\`, or \`no-store\`. ```ts string ``` * maxAge The maximum amount of time in seconds that a resource will be considered fresh. See \`max-age\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#:\~:text=Response%20Directives-,max%2Dage,-The%20max%2Dage). ```ts number ``` * staleWhileRevalidate Indicate that the cache should serve the stale response in the background while revalidating the cache. See \`stale-while-revalidate\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-while-revalidate). ```ts number ``` * sMaxAge Similar to \`maxAge\` but specific to shared caches. See \`s-maxage\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#s-maxage). ```ts number ``` * staleIfError Indicate that the cache should serve the stale response if an error occurs while revalidating the cache. See \`stale-if-error\` in the \[MDN docs]\(https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#stale-if-error). ```ts number ``` ### CartMetafieldDeleteFunction * key ```ts string ``` * optionalParams ```ts CartOptionalInput ``` Promise\ ```ts Promise ``` ### CartOptionalInput * cartId The cart id. ```ts string ``` * country The country code. ```ts CountryCode ``` * language The language code. ```ts LanguageCode ``` ### CartQueryDataReturn ```ts CartQueryData & { errors?: StorefrontApiErrors; } ``` ### CartQueryData * cart ```ts Cart ``` * userErrors ```ts CartUserError[] | MetafieldsSetUserError[] | MetafieldDeleteUserError[] ``` ### Cart ### CartUserError ### MetafieldsSetUserError ### MetafieldDeleteUserError Examples ### Examples * #### example ##### Description This is the default example ##### JavaScript ```js import {cartMetafieldDeleteDefault} from '@shopify/hydrogen'; const cartDeleteMetafield = cartMetafieldDeleteDefault({ storefront, getCartId, }); const result = await cartDeleteMetafield('namespace.key'); ```