Expiration Data Assigned to an Order
Expiration data assigned to orders can be made available to external systems as an order property. An order property is used because Shopify does not support metafields for order line items. To enable this property check "Create an order attribute for an order's inventory batches" from the Orders tab on the settings page.
Orders placed before this option was enabled will not contain the property.
Order Property Format
Once enabled order attributes named Expiration Dates SKU will be added to orders containing expiration data. SKU will be replaced with the value of the product's SKU. The attribute's value is in the following format: BATCH 1|BATCH 2|BATCH 3.
For example, if you have a product with a SKU of 123 that is assigned a single batch you will have an attribute named Expiration Dates 123 with a value of: 2024-01-01,1,B123. Here 2024-01-01 is the assigned expiration date, 1 is the quantity assigned, and B123 is the batch number.
If the order line has multiple batches they will be included. For example, if SKU 123 was assigned 2 batches, the value would be: 2024-01-01,1,B123|2024-11-21,2,X999. Here 2024-01-01 is 1 of 2 assigned expiration dates. 1 the quantity assigned and B123 is its batch number. 2024-11-21 is the other assigned expiration date. 2 is its quantity assigned and X999 its batch number.
If a batch number (or any value) does not exist its value will be omitted. Here's the multiple batch example without a batch number: 2024-01-01,1,|2024-11-21,2,
Parsing the Property's Value
Parsing the value can be done in any language by retrieving the order's attributes via the Shopify Admin API. Here's an example using Liquid:
{% assign batches = order.attributes["Expiration Dates 123"] | split: "|" %}
{% for batch in batches %}
{% assign batch_data = batch | split: "," %}
{% assign expires_date = batch_data[0] %}
{% assign expires_qty = batch_data[1] %}
{% assign expires_batch = batch_data[2] %}
Expires: {{ expires_date | date: "%d/%m/%Y" }} ({{expires_quantity}})
Batch {{ expires_batch }}
{% endfor %}