How get product by id inside liquid template?

01familia
Excursionist
17 0 4

Hello

I would like to get a product by ID but I don't know how to do that.

The product ID is 2

Please don't tell me "you can use all_products" using this code:

 

 {% for product in collections.all.products %}
       {% if product.id == 2 %}
            {% assign my_product = product %} 
      {% endif %}
 {% endfor %}

 

or:

{{ all_products['2'] }}

 

I cannot use "all_products" because I have many many products (10000 products).
And I cannot create many  many many collections only to get product by id.

Indeed : The all_products object has a limit of 20 unique handles per page. If you want more than 20 products, then consider using a collection instead.

Source: https://shopify.dev/api/liquid/objects#all_products

Screen Shot 2021-07-01 at 11.26.02.png

So, if a shopify employee reads this post (for example an engineer), can you show me the liquid code to get a product by ID?

Thank you so much.

Best Regards 

 

 

0 Likes
HerculesApps
Tourist
8 1 8

Hello could you find a way to get product by id?

Getting product by handle is not a good way for me, because people can change the handle in the product settings.

0 Likes
HerculesApps
Tourist
8 1 8

 

{% for product in collections.all.products %}
{% if product.id == 6687973638353 %}
{% assign shopifyProduct = product %}
{% endif %}
{% endfor %}

 

This works.

0 Likes