Searching a specific product from the liquid file.

Searching a specific product from the liquid file.

Wakil_eFoli
Shopify Partner
47 2 6

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
406 60 58

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 (Mail: js.sbu@brainstation-23.com)
- Was your question answered? Mark it as an Accepted Solution
- Did the solution not address your concern? We kindly request that share or mail your store URL with us this will enable us to collaborate more closely.
- Explore our Shopify public apps