{% comment %} Used by the Product Expiration Dates app to display a product's expiration date on the product page and show/hide expiration dates based on the selected variant (if any). Usage: Make the folling call wherever you want to the date to be displayed: {% render "ss-product-expiration-dates", product: product, prefix: "Best Before", format: "%d/%m/%Y" %} You can include HTML in the prefix value: {% render "ss-product-expiration-dates", product: product, prefix: "Best Before", format: "%d/%m/%Y" %} If you want to only show the expiration date when it's close to a particular number of days: {% render "ss-product-expiration-dates", product: product, prefix: "Best Before", format: "%d/%m/%Y", expires_window_days: 21 %} If you want to display the batch number: {% render "ss-product-expiration-dates", product: product, prefix: "Best Before", format: "%d/%m/%Y", batch_number: true, batch_prefix: "Batch" %} If you want to show the expiration dates on a page that never shows the product variant selectors, like the cart page, you should instruct the snippet not to look for them to avoid unwanted side effects: {% render "ss-product-expiration-dates", product: product, variant_selection: false, prefix: "Best by", format: "%B %d, %Y" %} For support contact help@screenstaring.com {% endcomment %} {% assign seconds_in_a_day = 86400 %} {% assign default_variant = product.selected_or_first_available_variant %} {% assign bundle = product.selected_or_first_available_variant.metafields.expiration_dates.bundled_inventory %} {% assign allocation = default_variant.metafields.expiration_dates.allocations[0] %} {% assign use_within = default_variant.metafields.expiration_dates.use_within %} {% if bundle != blank %} {% if show_bundle %}
{% for bundled_product in bundle %} {% assign allocation = bundled_product.allocations[0] %} {% if allocation != blank %}
{% unless bundled_product_title == false %} {{ bundled_product.title }} - {% endunless %} {% if prefix != blank %} {{ prefix | downcase }} {% endif %} {{ allocation.time | date: format }} {% if suffix != blank %} {{ suffix }} {% endif %}
{% endif %} {% endfor %}
{% endif %} {% elsif show_expiration_date or show_batch_number or show_use_within %}
{% if show_expiration_date %} {%- if allocation != blank and prefix != blank -%} {{ prefix }} {%- endif -%} {%- if allocation != blank -%} {{ allocation.time | date: format }} {%- endif -%} {%- if allocation != blank and suffix != blank -%} {{ suffix }} {%- endif -%} {% endif %} {%- if show_batch_number and allocation != blank and allocation.batch_number != blank -%} {%- if batch_prefix -%} {{ batch_prefix }} {{ allocation.batch_number }} {%- else -%} ({{ allocation.batch_number }}) {%- endif -%} {%- endif -%} {% if show_use_within and use_within.use_within_value_in_days != blank %} {%- if use_within_prefix != blank -%} {{ use_within_prefix }} {%- endif -%} {{ use_within.use_within_value }} {{ use_within.use_within_units }} {% endif %}
{% endif %}