Bookable Type

A bookable product such as an Event, Course or Service, has a bookable_typefield on its Variant's metafields.bookings object, which can be useful for displaying the type of product or determining where to look for additional metadata about a bookable type.

Displaying a Bookable's Type

{% for product in collection.products %}
  {% assign current_variant = selected_or_first_available_variant %}
  {% assign metafields = current_variant.metafields.bookings %}
  
  {% if metafields != blank %} // Bookable Product
    {{metafields.bookable_type}}
  {% else %} // Not a bookable product
    {{product.type}}
  {% endif %}
{% endfor %}

Accessing Metafields Based on a Bookable's Type

{% for product in collection.products %}
  {% assign current_variant = selected_or_first_available_variant %}
  {% assign metafields = current_variant.metafields.bookings %}
  {% case metafields.bookable_type %}
    {% when 'event' %}
      <p>Start time: {{ metafield.starts_at }}</p>
      <p>End time: {{ metafield.ends_at }}</p>
    {% when 'course' %}
      <p>Course Sessions:</p>
      {% for session in metafields.sessions %}
       <p>Start time: {{ session.starts_at }}</p>
       <p>End time: {{ session.ends_at }}</p>
      {% endfor %}
    {% when 'service' %}
      <p>{{ product.title }}</p>
      <p>Start time: {{ metafield.starts_at }}</p>
      <p>End time: {{ metafield.ends_at }}</p>
    {% else %}
      This product is not bookable
  {% endcase %}
{% endfor %}

Last updated