Following is a collection of useful Liquid snippets, to help with common changes/modifications.

Note: This is intended for advanced users, who are comfortable working with HTML, CSS and Liquid code. It's also a nice reference for myself, when helping customers update templates 😉

Shopify Liquid Documentation

https://shopify.github.io/liquid/


Adding days to a date (example, add XX days to order creation date)

{% assign days_as_seconds = XX | times: 24 | times: 60 | times: 60 %}
{{ created_at | date: "%s" | plus: days_as_seconds | date: "%Y-%m-%d" }}

Replace XX in the above code with the number of days you want to add.


Display line item in one row per quantity (useful in Packing Slips)

{% for i in (1..line_item.quantity) %}


Skip to next line item, if quantity is less than 1.

{% if line_item.quantity < 1 %}{% continue %}{% endif %}



Adding HS Tariff Codes and Country of Origin

{% if line_item.hs_tariff_code != blank %}
<p class="item-description-line">HS Tariff Code: {{ line_item.hs_tariff_code }}</p>
{% endif %}
{% if line_item.country_of_origin != blank %}
<p class="item-description-line">COO: {{ line_item.country_of_origin }}</p>
{% endif %}

Show only Zapiet Pickup Date and Pickup Time attributes

{% for attribute in attributes %}

{% if attribute.first != "Pickup-Date" or attribute.first != "Pickup-Time" %}{% continue %}{% endif %}

{% assign a_internal = attribute.first | slice: 0 %}

{% unless a_internal == "_" %}

<br><b>{{ attribute.first | replace: "-", " " | replace: "_", " " | capitalize }}:</b> {{ attribute.last | newline_to_br }}

{% endunless %}

{% endfor %}


Show Gift Card amount and deduct from Total Price

{% assign gift_card_total_price = 0 %}

{% for transaction in transactions %}

{% if transaction.status == "success" %}

{% if transaction.kind == "sale" or transaction.kind == "capture" %}

{% if transaction.gateway == "gift_card" or transaction.gateway == "Gift Card" or transaction.gateway == "Gift card" %}

{% assign gift_card_total_price = gift_card_total_price | plus: transaction.amount %}

{% endif %}

{% endif %}

{% endif %}

{% endfor %}

{% if gift_card_total_price != 0 %}

<tr>

<td class="pricing-table-title editable" data-key="total_tax">Geschenkkarte</td>

<td class="pricing-table-text">-{{ gift_card_total_price | money }}</td>

</tr>

{% endif %}

<tr class="pricing-table-total-row">

<td class="pricing-table-title"><span class="editable" data-key="total"><b>GESAMTBETRAG</b></span></td>

<td class="pricing-table-text">{{ total_price | minus: gift_card_total_price | money }}</td>

</tr>

Did this answer your question?