How can I check whether a product variant contains a specific metafield?

Topic summary

A developer is building a theme block that should only display for product variants containing a specific metafield.

Current Approach:

  • Looping through product variants in Liquid to create a list of variants with the target metafield
  • This method has a limitation: only 100 variants can be iterated this way

Challenge:

  • Shopify now supports up to 2000 variants per product, making the current solution inadequate
  • Unable to retrieve metafields for a product variant using the AJAX API

Potential Alternative:

  • Tracking variant changes and requesting variant information via AJAX API using JavaScript

Partial Response:

  • Another user suggests that product.variants in Liquid should support all 2000 variants and can iterate over them using standard Liquid markup in the developer preview

The discussion remains open regarding the best method to handle metafield checks across large variant sets.

Summarized with AI on November 8. AI used: claude-sonnet-4-5-20250929.

I am sure the product.variants in liquid will support 2000 variants since on developer preview it can already iterate over 2000 variants using the following

{%for variant in product.variants %}