Can I create a custom discount sorting option in Shopify?

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 != 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">{{ }}</span>
{%- 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>
Replies 0 (0)