Can I create a custom discount sorting option in Shopify?

Frez
Visitor
1 0 0

I'm wondering if Shopify supports any way of adding new custom sorting objects. Like the sort_option :

 

{
"name": "Alphabetically, A-Z",
"value": "title-ascending"
}

 

What I would like to do is add a option to sort by the amount of discount a product has. So sort based on something like this for each product: 

 

{% assign discount = product.compare_at_price | minus: product.price %}

 

And if this is the proper way of adding a button for that?:

 

<x-listbox class="popover__value-list">
{%- for sort_option in collection.sort_options -%}
{%- if sort_option.name != blank -%}
<button type="button" class="popover-listbox__option group" role="option" value="{{ sort_option.value }}" {% if sort_option.value == selected_sort_by_value %}aria-selected="true"{% endif %}>
<span class="reversed-link">{{ sort_option.name }}</span>
</button>
{%- endif -%}
{%- endfor -%}

<!-- Custom sort option for discount percentage -->
<button type="button" class="popover-listbox__option group" role="option" value="discount_percentage">
<span class="reversed-link">Sort by discount</span>
</button>
</x-listbox>
Replies 0 (0)