Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zakhardage/6537d5096ed0cd9ee46f9beb49d8d11f to your computer and use it in GitHub Desktop.
Save zakhardage/6537d5096ed0cd9ee46f9beb49d8d11f to your computer and use it in GitHub Desktop.
Removes duplicate strings from the beginning of variant titles (Shopify)
{% assign string = product.variants[0].title | downcase | split:' ' %}
{% assign size = string | size %}
{% assign pass = true %}
{% for i in (0..size) %}
{% for variant in product.variants %}
{% assign compare = variant.title | downcase | split:' ' %}
{% unless string[i] == compare[i] %}{% assign pass = false %}{% endunless %}
{% endfor %}
{% if pass %}{% assign remove = remove | append:string[i] | append:' ' %}{% endif %}
{% endfor %}
<select name="id" class="product-select">
{% for variant in product.variants %}
<option value="{{ variant.id }}">{{ variant.title | downcase | remove:remove }}</option>
{% endfor %}
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment