Product variants code

Hello @sagabikes ,

To display unique delivery times for each variant, follow these steps:

Go to Dashboard → Settings → Custom Data. Navigate to Variants, add a definition, and name it “Variant Message”. Select the type “Single Line Text”.

Next, go to the products where you want to display delivery times. Open any product, select a variant, click on Bulk Edit, then add a new column for “Variant Message”. Enter the desired delivery time for each variant and save the product.

Finally, go to Online Store → Edit Code. Add a new snippet file named variant-message.liquid, and paste the relevant code into this file. Then, search for the main-product.liquid file, open it, find the word “buy”, and paste the code there. You can refer to the screenshot for guidance.


  {% for variant in product.variants %}
  {% if variant.id == product.selected_or_first_available_variant.id %}
  {% assign default_variant = variant %}
  

    {{ default_variant.metafields.custom.variant_message }}
  

  {% else %}
  

    {{ variant.metafields.custom.variant_message }}
  

  {% endif %}
  {% endfor %}

{% render 'variant-message' %}