use App Metafieldshook
Returns the metafields configured with shopify.ui.extension.toml
.
Anchor to useAppMetafields-parametersParameters
- Anchor to filtersfiltersDefault: {}
UseAppMetafieldsGeneratedType
Returns the metafields configured with `shopify.ui.extension.toml`.
- filters
AppMetafieldFilters
AppMetafieldEntry[]
export function useAppMetafields<
ID extends RenderExtensionPoint = RenderExtensionPoint,
>(filters: AppMetafieldFilters = {}): AppMetafieldEntry[] {
const appMetafields = useSubscription(useApi<ID>().appMetafields);
return useMemo(() => {
if (filters.key && !filters.namespace) {
throw new CheckoutUIExtensionError(
'You must pass in a namespace with a key',
);
}
const filterKeys = Object.keys(filters) as AppMetafieldFilterKeys[];
if (filterKeys.length) {
return appMetafields.filter((app) => {
return filterKeys.every((key) => {
if (key === 'id' || key === 'type') {
return app.target[key] === filters[key];
}
return app.metafield[key] === filters[key];
});
});
}
return appMetafields;
}, [filters, appMetafields]);
}
AppMetafieldFilters
- id
string
- type
"customer" | "product" | "shop" | "variant" | "company" | "companyLocation" | "cart"
- namespace
string
- key
string
interface AppMetafieldFilters {
id?: AppMetafieldEntryTarget['id'];
type?: AppMetafieldEntryTarget['type'];
namespace?: Metafield['namespace'];
key?: Metafield['key'];
}
AppMetafieldEntry
A metafield associated with the shop or a resource on the checkout.
- target
The target that is associated to the metadata. {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`.
AppMetafieldEntryTarget
- metafield
The metadata information.
AppMetafield
export interface AppMetafieldEntry {
/**
* The target that is associated to the metadata.
*
* {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`.
*/
target: AppMetafieldEntryTarget;
/** The metadata information. */
metafield: AppMetafield;
}
AppMetafieldEntryTarget
The metafield owner.
- type
The type of the metafield owner. {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`.
"cart" | "customer" | "product" | "shop" | "variant" | "company" | "companyLocation"
- id
The numeric owner ID that is associated with the metafield.
string
export interface AppMetafieldEntryTarget {
/**
* The type of the metafield owner.
*
* {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`.
*/
type:
| 'customer'
| 'product'
| 'shop'
| 'variant'
| 'company'
| 'companyLocation'
| 'cart';
/** The numeric owner ID that is associated with the metafield. */
id: string;
}
AppMetafield
Represents a custom metadata attached to a resource.
- key
The key name of a metafield.
string
- namespace
The namespace for a metafield.
string
- value
The value of a metafield.
string | number | boolean
- valueType
The metafield’s information type.
"string" | "boolean" | "integer" | "json_string" | "float"
- type
The metafield's type name.
string
export interface AppMetafield {
/** The key name of a metafield. */
key: string;
/** The namespace for a metafield. */
namespace: string;
/** The value of a metafield. */
value: string | number | boolean;
/** The metafield’s information type. */
valueType: 'boolean' | 'float' | 'integer' | 'json_string' | 'string';
/** The metafield's type name. */
type: string;
}