Request for Liquid Code Modification to Accurately Display Product Availability

Topic summary

A Shopify store owner is seeking help to modify Liquid code that displays product availability status. The current implementation doesn’t properly account for incoming stock transfers when determining what message to show customers.

Current Issue:

  • The existing code fails to look ahead through multiple incoming stock batches
  • It doesn’t accurately determine when backordered items will be available based on future transfers

Desired Logic:

  • Iterate through all incoming stock batches to collect dates and quantities
  • Calculate combined inventory (current stock + total incoming quantities)
  • Identify the earliest incoming date
  • Display messages based on combined inventory:
    • If combined inventory ≤ 0: Show “Ready to ship” with earliest incoming date, or “Made to order” if no incoming stock
    • If combined inventory > 0: Show “In stock”

Code Provided:
The user shared updated Liquid code that tracks backordered quantities and attempts to find the next available date by iterating through incoming stock. However, portions of the code appear corrupted or reversed in the original post.

Status: The discussion remains open with no solution provided yet. The user is looking for code modifications to accurately reflect product availability considering future stock transfers.

Summarized with AI on November 11. AI used: claude-sonnet-4-5-20250929.

Objective: Modify the stock status display logic on the product page in Shopify to accurately reflect the availability of stock considering incoming stock transfers.

Current Logic (Summary):

  1. Retrieve the current date and the date of the next incoming stock transfer.
  2. Calculate the difference in weeks between the current date and the next incoming date.
  3. Determine if the product is in stock based on the current inventory and incoming stock.
  4. Display appropriate messages based on the stock status.

Proposed Modifications:

  1. Iterate through each incoming stock batch to collect the dates and quantities.
  2. Calculate the combined inventory considering both the current inventory and total incoming quantities.
  3. Determine the earliest incoming date from the collected dates.
  4. If the combined inventory is zero or negative:
    • Check if there’s an earliest incoming date.
      • If yes, display a “Ready to ship” message with the earliest incoming date.
      • If no, display a “Made to order” message with the standard lead time.
  5. If the combined inventory is positive, display an “In stock” message.

Code Implementation (Summary):

  1. Initialize variables for current date, incoming dates, incoming quantities, and combined inventory.
  2. Iterate through incoming stock batches to collect dates and quantities.
  3. Calculate combined inventory considering current inventory and total incoming quantities.
  4. Determine the earliest incoming date.
  5. Based on combined inventory and incoming dates:
    • Display appropriate stock status messages.

The below code is working pretty good, just doesn’t take into account if the very next stock transfer is spoken for and to look ahead to which stock transfer the customer will be able to reserve product on. I have attached the HTML for reference

" {% assign current_date = ‘now’ | date: ‘%s’ %} {% assign incoming_date = product.variants.first.next_incoming_date | date: ‘%s’ %} {% assign seconds_in_week = 604800 %} {% if incoming_date != blank %} {% assign difference_in_seconds = incoming_date | minus: current_date %} {% assign weeks_until_ship = difference_in_seconds | divided_by: seconds_in_week | plus: 1 %} {% assign formatted_incoming_date = product.variants.first.next_incoming_date | date: “%B %d, %Y” %} {% assign combined_inventory = product.variants.first.inventory_quantity %} {%- comment -%} Loop through incoming stock batches to calculate the total incoming quantity. {%- endcomment -%} {% for stock_batch in product.variants.first.incoming_stock_batches %} {% assign combined_inventory = combined_inventory | plus: stock_batch.quantity %} {% endfor %} {% if combined_inventory <= 0 %} Ready to ship in approximately {{ weeks_until_ship | round }} weeks ({{formatted_incoming_date}}). {% else %} In stock and ready to ship now. More incoming stock due by {{ formatted_incoming_date }}. {% endif %} {% elsif product.variants.first.inventory_quantity > 0 %} In stock and ready to ship now. {% else %} Made to order. Current lead time 10-14 weeks.</s "

Sorry here is the updated code we have been using

"

{% assign current_stock_level = product.variants.first.inventory_quantity %}
{% assign backordered_quantity = 0 %}

{% if current_stock_level < 0 %}
{% assign backordered_quantity = current_stock_level | abs %}
{% endif %}

{% assign cumulative_stock = current_stock_level %}
{% assign next_available_date = blank %}
{% assign found_stock = false %}

{% for stock in product.variants.first.incoming_stock %}
{% if backordered_quantity > 0 %}
{% assign cumulative_stock = cumulative_stock | plus: stock.quantity %}
{% if cumulative_stock >= 0 %}
{% assign next_available_date = stock.date %}
{% assign found_stock = true %}
{% break %}
{% else %}
{% assign backordered_quantity = backordered_quantity | minus: stock.quantity %}
{% endif %}
{% endif %}
{% endfor %}

{% if found_stock %}
{% assign formatted_incoming_date = next_available_date | date: “%B %d, %Y” %}
Backordered. Estimated restock date: {{ formatted_incoming_date }}.
{% elsif current_stock_level > 0 %}
In stock and ready to ship now.
{% else %}
Currently out of stock. Check back soon for updates.
{% endif %}"