Customization

Liquid Product Variants

Handling Product Variants

Liquid product variants manage Shopify product options and prices.

Introduction to Liquid Product Variants

Liquid product variants are used in Shopify to manage different options of a product, such as size and color, and their respective prices. This allows for a dynamic shopping experience where customers can choose from various product attributes.

Setting Up Product Variants in Shopify

Before using Liquid to manipulate product variants, ensure that your Shopify product has variants set up in the admin panel. You can create variants by adding options like size, color, or material. Each combination of options results in a unique variant.

Accessing Product Variants with Liquid

In Liquid, you can access product variants using the variants attribute on a product object. This allows you to loop through all the available variants for a product.

Displaying Product Variant Options

To display variant options on a product page, you can use a form. This enables customers to select their preferred variant before adding it to their cart. Here's a basic example:

Customizing Variant Display

You can customize the display of product variants by using conditional logic in Liquid. For example, you might want to display a message if a variant is out of stock:

Managing Prices with Product Variants

Product variants allow you to set different prices for different options. In Liquid, you can easily display the correct price by accessing the price attribute of a variant object.