Is it possible to know when the customer added items to the cart in cart and checkout validation function?

Hello,

Is it possible to know when the customer added items to the cart in cart and checkout validation function?
We want to disable checkout if the customer added the items outside business hours?

Thank you!

Hi @remy727 I don’t think that native objects provide a timestamp indicating when each product was added to the cart.

As a workaround, you could add a custom line item property with the add-to-cart form. For example, something like "_added_at": "2024-12-19T14:05:00Z":

<form action="/cart/add" method="post" enctype="multipart/form-data">
  <input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}" />

  <!-- Custom line item property -->
  <input type="hidden" name="properties[_added_at]" value="{{ 'now' | date: '%Y-%m-%dT%H:%M:%S%z' }}" />

  <button type="submit">Add to cart</button>
</form>

LocalTime type in the schema.graphql file for Shopify Functions is designed primarily for comparing given times and dates. However, it does not include a direct field or method to retrieve the current time .

Use the dateTimeAfter field, it returns true if the current date and time is at or past the given date and time, and false otherwise.