Back to blog

Shopify Hack: Merge Variants on a Single Product Page

3 min
Wojciech Kałużny
Wojciech Kałużny

Shopify imposes certain limits on product variants to maintain a streamlined experience for users and manage performance effectively. Specifically, Shopify allows up to 100 variants per product and supports up to 3 options (like size, color, or material) per product. This can become problematic for businesses that offer extensive product lines with numerous variations.

When a product reaches these limits, you face several challenges:

  • Product Management: Handling more than 100 variants can become cumbersome. Merchants must either create additional listings or simplify their product offerings, both of which can complicate inventory management and negatively impact the user experience.
  • Customer Experience: Shoppers may find it confusing to navigate between multiple product listings that essentially offer the same item but with different variations. This fragmentation can lead to a poor user experience and potentially lost sales.
  • Store Organization: Splitting variants across multiple product pages can clutter the store, making it harder for customers to find what they're looking for and for store owners to maintain a clean, organized inventory.

If you're facing these issues, our experienced Shopify Developers Services can help you navigate these limitations and create custom solutions tailored to your store’s needs.

Combining Variants into a Single Product Page

To address these limitations, you can leverage Shopify’s metafields and Liquid code to aggregate variants from multiple products into a single product page. This approach allows you to bypass the variant limit by linking additional products (referred to as "child products") to a primary product.

Our Shopify App Development team can also build custom apps that extend Shopify’s functionality, including the ability to manage complex product catalogs and streamline variant management.

Create a Custom Metafield for Child Products

  1. Define the Metafield:
  • In your Shopify admin, navigate to Settings > Metafields > Products.
  • Create a new metafield definition, naming it something like connection.child_products.
  1. Configure it to accept multiple product references.
  2. Assign Child Products:
  • For each main product that exceeds the variant limit, assign relevant child products using this metafield. These child products will be linked but not directly listed as separate items.

Need assistance setting up custom metafields? Explore our Shopify services to get expert help.

Update Product Page Code to Include Child Product Variants

When dealing with Shopify's variant limits, ensuring that all your product variants appear on a single page can feel like trying to fit a square peg into a round hole. Fortunately, with a bit of Liquid code, you can combine all the variants from your main product and its related child products into one seamless display.

To start, you'll need to adjust the Liquid code in your product template to pull in variants from both the main product and any connected child products. Here’s how you can do it:

{%- liquid
  assign child_products = product.metafields.connection.child_products.value
  assign variants = product.variants
  assign media = product.media
  
  // Add child_products data to variants and media
  for sub_product in child_products
    assign variants = variants | concat: sub_product.variants
    assign media = media | concat: sub_product.media
  endfor
-%}

For more context, let me explain

  • child_products: Retrieves the products linked to the main product through the custom metafield "child_products."
  • variants and media: Initially assigned the main product's variants and media, then expanded to include those from the child products.

Update rendering logic in corresponding templates

To make sure all these combined variants appear on your product page, you’ll need to adjust how variants and media files are rendered. Essentially, you'll replace product.variants and product.media with your newly aggregated variants and media collections. Here's what that looks like:

// main-product.liquid
{% render 'product-variant-select', product: product, block: block, product_form_id: product_form_id %}
// changes to
{% render 'product-variant-select', variants: variants product: product, block: block, product_form_id: product_form_id %}

// snippets/product-variant-select.liquid
{%- for variant in product.variants -%}
# changes to 
{%- for variant in variants -%}

The sections/main-product.liquid file is where you call the variant selection snippet, now passing in the aggregated variants collection instead of just product.variants.

In the snippets/product-variant-select.liquid file, the loop is adjusted to iterate over variants instead of product.variants, ensuring all the variants from both the main product and its child products are displayed.

Once these changes are in place, your product pages will seamlessly display all variants from the connected products. This means your customers can view and select from the full range of options without navigating between multiple listings.

Wrapping It Up

By creating custom metafields and tweaking your product page code, you can effectively bypass Shopify's variant limits. This approach not only simplifies how you manage your inventory but also provides a smoother, more comprehensive shopping experience for your customers. No more juggling multiple product pages—everything they need is right there in one place!

Ready to take your Shopify store to the next level? Whether you need Shopify Development or specialized Shopify Apps Development, our expert team is here to help you achieve your e-commerce goals.

More articles

SaaS Pricing: 6 Steps To Nail Your Pricing

Tim Davidson

Do I Need A Business Website?

Tim Davidson

Product Hunt Launch Failed: What Now?

Tim Davidson