I need some syntax help adding a statement.

While pretty comfortable with coding, this is in a critical area and I want to get it right.

In snippets/product-price.liquid I want to add the words " per serving" after any item in the collection of “Catering.” In plain language, “if the item is in the collection “Catering,” show the words “per serving” after the price, else just show the price.” I tested just adding " per serving" to any product and that works fine. I just need to add the if-then-else to only do it for Catering products.

This original code is found in snippets/product-price.liquid :

{% if available %}
      {% if product.price_varies and template == 'collection' %}
          From {{ product.price_min | money }} to {{ product.price_max | money }}
       {% else %}
           {{ money_price }}
       {% endif %}
{% else %}
       {{ 'products.product.sold_out' | t }}
{% endif %}

I need help with the section that starts with the if product collection. I’m not sure of the syntax and variables of that statement.

{% if available %}
     {% if product.price_varies and template == 'collection' %}
         From {{ product.price_min | money }} to {{ product.price_max | money }}
     {% else %}
         {% if product.collection == "Catering" %}
               {{ money_price | append: " per serving" }}
         {% else %}
               {{ money_price }}
         {% endif %}
      {% endif %}
{% else %}
      {{ 'products.product.sold_out' | t }}
{% endif %}

Thanks in advance.

@Desdinova - need to update product.collection as it would be product.collections which returns an array of collections, so can be made like below

{% if available %}
     {% if product.price_varies and template == 'collection' %}
         From {{ product.price_min | money }} to {{ product.price_max | money }}
     {% else %}
         {% if product.collections contains 'Catering' %}
               {{ money_price | append: " per serving" }}
         {% else %}
               {{ money_price }}
         {% endif %}
      {% endif %}
{% else %}
      {{ 'products.product.sold_out' | t }}
{% endif %}

That didn’t work, and I think it really should have. I didn’t get an error it just didn’t acknowledge that “catering” was in the collection.
However, and THANK YOU for pointing me in the right directly… product.type contains ‘Catering Menu’ worked like a charm.

Thoughts?

1 Like

@Desdinova - congratulations, nice to know that the problem is solved