Headless commerce and custom storefronts with Shopify APIs and SDKs
I have added metafields for products and then via the collection page created custom filters which work:
{%- for filter in collection.filters -%}
<script>console.log({{ filter.active_values | json }});</script>
<div class="form-horizontal">
<label for="{{ filter.label }}" style="text-transform: capitalize;">{{ filter.label }}</label>
<select name="{{ filter_value.param_name }}" id="{{ filter_value.param_name }}" class="btn--tertiary" onChange="window.document.location.href=this.options[this.selectedIndex].value;">
{%- for filter_value in filter.values -%}
<option value="{{ collection.url }}?{{ filter_value.param_name }}={{ filter_value.value }}">{{ filter_value.label }}</option>
{%- endfor -%}
</select>
</div>
{%- endfor -%}
Which creates nice custom filtering:
When a user chooses a drop down item/filter it redirects the user to a page like:
/collections/shop?filter.p.m.custom.categories=Knitwear
But I can't work out how to extract the active filter (filter.p.m.custom.categories) value (Knitwear) or get the URL GET param in order to set the dropdown default (selected) value so that the dropdown shows the active filter in place.
I would prefer to do in liquid if possible? or do I have to use JavaScript to sort?
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022