I have the below code in my shopify site, currently all it does is display a link to either 'in stock' or 'Show All'. I would like to make the link more dynamic so if someone has filtered by a certain product and they click on the "in stock" link it would show only in stock for that product. eg. if they were at /collections/all/Product1 after clicking the link it should go to /collections/in-stock/Product1
My Current code:
<div class="filter-stock">
{% if page_title contains "Products" %}
<a href="/collections/in-stock"><b>Hide 'Sold Out' items</b></a>
{% endif %}
{% if page_title contains "IN STOCK" %}
<a href="/collections/all"><b>Show All Products</b></a>
{% endif %}
New Code which seems to work:
<div class="filter-stock">
{% if current_tags %}
{% for tag in current_tags %}
{% if collection == blank or collection.handle != 'in-stock' %}
<a href="/collections/in-stock/{{ tag | handleize }}"><b>Hide 'Sold Out' items</b></a>
{% endif %}
{% if collection and collection.handle == 'in-stock' %}
<a href="/collections/all/{{ tag | handleize }}"><b>Show All Products</b></a>
{% endif %}
{% endfor %}
{% else %}
{% if collection == blank or collection.handle != 'in-stock' %}
<a href="/collections/in-stock"><b>Hide 'Sold Out' items</b></a>
{% endif %}
{% if collection and collection.handle == 'in-stock' %}
<a href="/collections/all"><b>Show All Products</b></a>
{% endif %}
{% endif %}
</div>
I would have it set up something like this: