Determining the status of a Course or Event can be useful for displaying conditional UI or messaging.
Course
A courses status can be determined by a combination of its session's metadata and product info coming from Shopify:
Sold Out
A course can be considered Sold Outif the course has not yet begun (e.g. the course's first session's starts_at is in the future) and the Product is no longer available.
Closed for Registration
A course can be considered Closed for Registration if the course has begun (e.g. the course's first session's starts_at is in the past)
{% assign current_variant = product.selected_or_first_available_variant %}
{% assign course_bookings_metafields = current_variant.metafields.bookings %}
// Sorted in ASC order
{% assign sessions_sorted = course_bookings_metafields.sessions | sort: 'starts_at' %}
{% assign course_starts_at = sessions_sorted.first.starts_at | date: '%s' %}
{% assign todays_date = 'now' | date: '%s' %}
{% if todays_date > course_starts_at %}
This Course is `Closed for Registration`
{% endif %}
In the Past
A course can be considered In the Past if all course sessions have passed (e.g. the courses last session's ends_at is in the past)
Event
An event's status can be determined by a combination of its metadata and product info coming from Shopify:
Sold Out
An event can be considered Sold Outif the event has not yet begun (e.g. the event'sstarts_at is in the future) and the Product is no longer available.
Closed for Registration
An event can be considered Closed for Registration if the event has begun (e.g. the event's start_at is in the past)
In the Past
An event can be considered In the Past if the event has passed (e.g. the event's ends_at is in the past)