Useful Liquid snippets

A collection of useful liquid snippets, for advanced users.

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/ {% 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 %} HS Tariff Code: {{ line_item.hs_tariff_code }}. {% endif %} {% if line_item.country_of_origin != blank %} COO: {{ line_item.country_of_origin }}. {% endif %} {% 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 == "_" %}. {{ attribute.first | replace: "-", " " | replace: "_", " " | capitalize }}: {{ 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 %} Geschenkkarte -{{ gift_card_total_price | money }} {% endif %} GESAMTBETRAG {{ total_price | minus: gift_card_total_price | money }}
Was this article helpful?

Still puzzling over something?

The agent has read this article โ€” and everything around it. Ask a follow-up and it answers in seconds.