Skip to content

Instantly share code, notes, and snippets.

@whistlerbrad
Last active April 17, 2019 19:25
Show Gist options
  • Save whistlerbrad/4dd0e27fcce2320bace6e7dc7d3daf32 to your computer and use it in GitHub Desktop.
Save whistlerbrad/4dd0e27fcce2320bace6e7dc7d3daf32 to your computer and use it in GitHub Desktop.
**Partial code** Adds pre-order tag in Pipeline. Replace first 49 lines of code with this.
{%- assign pre_order = false -%}
{%- assign pre_order_tag = false -%}
{% if product.tags contains 'pre-order' %}
{%- assign pre_order = true -%}
{%- assign pre_order_tag = true -%}
{% endif %}
{%- assign on_sale = false -%}
{%- if product.compare_at_price > product.price -%}
{%- assign on_sale = true -%}
{%- endif -%}
{%- assign sold_out = true -%}
{%- if product.available -%}
{%- assign sold_out = false -%}
{%- endif -%}
{%- assign new_product = false -%}
{%- assign published_date = product.published_at | date: "%s" -%}
{%- assign now_date = 'now' | date: "%s" -%}
{%- assign age_in_days = now_date | minus: published_date | divided_by: 60 | divided_by: 60 | divided_by: 12 -%}
{%- if age_in_days < settings.tag_new_limit -%}
{%- assign new_product = true -%}
{%- endif -%}
{%- assign sellout_tag = false -%}
{%- if sold_out and settings.tag_sellout -%}
{%- assign sellout_tag = true -%}
{%- endif -%}
{%- assign new_tag = false -%}
{%- if new_product and settings.tag_new -%}
{%- assign new_tag = true -%}
{%- endif -%}
{%- assign sale_tag = false -%}
{%- if on_sale and settings.tag_sale -%}
{%- assign sale_tag = true -%}
{%- endif -%}
{%- assign tagged = false -%}
{%- if sellout_tag or new_tag or sale_tag or pre_order_tag -%}
{%- assign tagged = true -%}
{%- endif -%}
{%- capture sticker -%}
{%- if tagged %}
{%- if pre_order_tag -%}
<div class="sticker sticker--pre_order">{{ 'Pre-Order' }}</div>
{%- elsif sellout_tag -%}
<div class="sticker sticker--sold">{{ 'products.product.sold_out' | t }}</div>
{%- elsif sale_tag -%}
<div class="sticker sticker--sale">{{ 'products.product.sale' | t }}</div>
{%- elsif new_tag -%}
<div class="sticker sticker--new">{{ 'products.product.new' | t }}</div>
{%- endif -%}
{%- endif -%}
{%- endcapture -%}
@whistlerbrad
Copy link
Author

Replace first 49 lines of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment