Searching a specific product from the liquid file.

Wakil_eFoli
Shopify Partner
43 2 4

I'm using app embeds and in my liquid file I've a variant id and I wanna find the corresponding product data using that variant_id.

How can I do that? 

 

Thanks!

Reply 1 (1)

BrainStation23
Shopify Partner
344 54 51

hi @Wakil_eFoli,

You have access to product data from the product page. In the product page you have access to the product object which has the variants property containing all variants available for that product. You can use a for loop to match the variant you want and show it in the UI. 

below is a dummy code for example

{% assign variant_id = "your_variant_id_here" %}
  {% for variant in product.variants %}
    {% if variant.id == variant_id %}
      <h1>{{ variant.title }}</h1>
      <p>{{ variant.price}}</p>
      <!-- Output any other relevant product data -->
    {% endif %}
{% endfor %}
Brain Station 23 PLC
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Email: js.team@brainstation-23.com