Skip to content

Public metafields

Public metafields expose product group data to your theme’s Liquid, the Shopify Storefront API, and any other app that reads product metafields. This is the only data Color Swatches publishes through this surface; variant swatches and other features stay internal to the app and its theme widget.

By default this group data lives in private (app-scoped) metafields that only Color Swatches itself can see. Turn the setting on when you want to render group swatches with your own Liquid, query them from a headless storefront, or share them with a search, filter, or SEO app.

  1. In the Color Swatches admin, go to Settings → Product groups → General.
  2. Check Enable public metafields and save.
The Enable public metafields checkbox in Settings, Product groups, General.

Saving triggers a full resync that writes every group to the public namespace. Small catalogues finish in under a minute; very large ones take longer.

You can disable the setting at any time. The public copies are removed, the private metafields stay in place, and the app keeps working without further changes.

The toggle controls a single product metafield:

  • Namespace: pl_swatches
  • Key: groups
  • Type: JSON
  • Owner: Product

In the Shopify admin you’ll find the definition under Settings → Custom data → Products, listed as “Platmart Swatches: Groups (public)”.

The Platmart Swatches: Groups (public) definition in Shopify admin under Settings, Custom data, Products.

Only products that belong to at least one group get this metafield.

The metafield value is always a JSON array, with one element per group the product belongs to. A product in a single-option group looks like this:

[
{
"group_id": 12345,
"option_name": "Color",
"type": "colors",
"display_for": "products_and_collections",
"linked": false,
"swatches": [
{
"handle": "backpack-black",
"name": "Black",
"type": "one_color",
"color_one": "#000000",
"color_two": null,
"image": null,
"out_of_stock": false
}
]
}
]

If the product belongs to several groups, the array has multiple elements. Multi-option groups expand to one element per option slot, each with the same swatches shape.

To render group swatches in your theme, see Reading swatch data in Liquid.

For headless storefronts, query the metafield field on a product through the GraphQL Storefront API:

query ProductSwatches($handle: String!) {
product(handle: $handle) {
id
title
swatchGroups: metafield(namespace: "pl_swatches", key: "groups") {
value
}
}
}

The value is a JSON string. Parse it client-side to get the same payload you’d see in Liquid.

Any Shopify app with the read_products access scope can read pl_swatches.groups like any other custom metafield. No special integration is needed.