Get variant by ID for the known product

I’m trying to find a specific variant using its ID, but I’ve run into an issue with the paginated variants on product.variants.

According to the docs, product.variants is limited to the first 250 variants. So when using find or where filters, they only search within those first 250 items.

For example:

assign variant = product.variants | find: 'id', variant_id
echo variant

Is there any workaround or alternative method to access a variant by ID beyond this limit, especially given the upcoming increase to 2048 variants per product? Searching only within the first 250 seems increasingly limiting.

Hi @Anton, I think you can try to work around it with preloaded variants via JavaScript, you can store them in a JavaScript object and then reference them dynamically. Liquid itself cannot bypass the 250 variant limit.

fetch(`/products/{{ product.handle }}.js`)
    .then(response => response.json())
    .then(data => {
        const variant = data.variants.find(v => v.id === VARIANT_ID);
        console.log(variant);
    });

You can also use GraphQL with pagination.

Thanks for the ideas, @lynthius!

I’ve tried fetching /products/{{ product.handle }}.js, but it seems that response is also limited to 250 variants, same as in Liquid.

The GraphQL route might be worth exploring for more advanced use cases, but in this case, I’m specifically looking for a way to access the variant object directly in Liquid.

Kind of ridiculous that I can’t look up a variant in Liquid when I have both the product and the exact variant ID.

Hey @Anton

For working with products that have more variants than this limit, we have a guide specifically on supporting high-variant products. This documentation covers the current best approaches for handling products that exceed the 250 variant limit in your theme.

If you have additional feedback after looking through these solutions, I’d be happy to pass it on to our product teams.

Thanks for the reply, @KyleG-Shopify!

Unfortunately, the approach outlined in the guide doesn’t work for our use case. The article focuses on using the selected variant logic based on option values passed through the URL, which works well on product pages.

However, our situation is different. We need to display variant information on a separate page (a bundle page), which shows details for multiple variants from different products that the buyer has selected. Since this isn’t the product page itself, the selected logic and URL-based option values aren’t applicable.

We already have access to the variant IDs, product references, and even the option value IDs, essentially all the data we could need. But we still haven’t found a way to retrieve the correct variant object from the product in Liquid given that information.

Happy to share more context if it’s helpful, and would appreciate it if this could be passed on as feedback to the product team.