Access app metafields
To perform advanced customizations or integrate swatches data with third-party apps, you need to access app metafields. This article explains how to enable public metafields so you can access swatch data in your Shopify theme or via API.
Why enabling public metafields?
By default, the app uses private metafields that are only accessible inside the app. To expose swatch data for theme rendering or third-party use, you need to enable public metafields. They are identical to private metafields, but accessible by third-parties.
How to enable public metafields
- Inside Platmart Swatches app go to Settings > General > Advanced.
- Enable the checkbox Use public app metafields and save changes.
Once enabled, the app will create a new metafield definition:
- Name: Platmart Swatches: Groups (public)
- Namespace:
pl_swatches.groups
This will make a copy of the swatch data available on the Product resource.
How to access swatch data
You can access this metafield from Liquid templates or via the Shopify API.
Example (Liquid):
{%- assign groups = product.metafields.pl_swatches.groups.value -%} {%- if groups -%} {%- for group in groups -%} {% for option in group.swatches %} {%- assign url = product.url | url_decode | replace: product.handle, option.handle | strip -%} <a href="{{ url }}"> {{ option.name }} {%- if product.handle == option.handle -%} (current) {%- endif -%} </a> {%- endfor -%} {%- endfor -%} {%- endif -%}
Example use cases:
- Building a custom swatches widget
- Using swatch data in product schema (for SEO)
- Integrating swatch with a third-party app
If you need more advanced example, feel free to contact us.