Access to app metafields

To perform deep customizations or integrate swatches data with third-parties, you gonna need to access app metafields. For our widgets, we use metafields with app-reserved namespace, that have limited access. To have full read access you need to enable public metafields. It can be done in Settings > General > Advanced:

Once enabled, the app will create new metafields definition called "Platmart Swatches: Groups (public)" and will expose a copy of swatches data under pl_swatches.groups key on Product resource.

You can read data from this metafield inside theme or via API. For example, here's how you can get a list of links from swatches in 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 -%}

Other example use cases:

  • Building custom swatches widget
  • Using swatches data in product schema (for SEO)
  • Integrating third-party app via API

If you need more advanced example for rendering swatches please contact support, and we'll help you.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us