All things Shopify and commerce
I want to add a tag on product to hide them on store front.
And i got solution for this
{%- for product in collection.products -%}
{% unless product.tags contains 'mytag' %}
{{ product.name }}
{% endunless %}
{%- endfor -%}
But after this, i got problem with paginate, some page have no item or just have few of them.
So, is there anyway to assign new variable with collection.product after filter them by tags not contain 'mytag'
{% assign polina_products = collection.products | where: 'vendor', "Polina's Potent Potions" %}
I found this, but is not help me somuch
You can create a new collection with the filtered products. Like first of all filter the products by tags using the code you provided and assign the filtered products to a new variable, such as "filtered_products." So, now you can paginate through the "filtered_products" variable instead of the original collection. This way, you'll ensure that pagination works correctly even after filtering products by tags. Here's how you can implement it:
{%- assign filtered_products = collection.products | where_exp: 'product', 'product.tags != "mytag"' -%}
{%- paginate filtered_products by 10 -%}
{% for product in paginate.collection %}
{{ product.name }}
{% endfor %}
{%- endpaginate -%}
See, if it works....
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025