11 min read • Updated 9 days ago
Manage product variants with Webflow CMS (Advanced)
Use Webflow CMS to manage variant groups, options, available inventory, and more.
Note
This article assumes you have already set up a Products CMS Collection and add to cart forms in Webflow. More information here.
Overview
By using Foxy and Webflow CMS to manage products and product variants, you'll be able to get around Webflow Ecommerce product variant limitations and add additional power features to your setup.
This approach consists of two CMS collections. One collection for products and another collection for product variants. The two are connected with a multi-reference field.
Features
The following features are supported (more in the works):
Multiple levels of variant groups
Select field and radio buttons
Dynamically styled radio buttons
Chained variant functionality
Per variant combination inventory control
Real-time image change
Real-time price change
Real-time sku change
Multilingual (with Webflow Localization, Weglot, and other services)
Multi-currency
Objectives
In this article, we'll accomplish the following:
Create product variants collection in Webflow CMS
Reference product variants from the products CMS collection
Set up variant group elements, select fields, and radio buttons in add to cart form
Configure variant snippet settings
Demo
Create Variants CMS Collection
An additional CMS collection is needed to store product variant data. Once you've created this additional CMS collection and have added data, you should have a CMS item for every possible product variant combination (ie: Awesome Shirt / Blue / Large).
Configure Add To Cart Form
You should have already set up add to cart forms following this article. The following modifications are needed for variants functionality:
Add Variant Fields
Our variant functionality supports select fields and radio buttons (default and custom). All variant groups can use the same field type, or you can mix them as needed (ie: Color uses radio buttons, Size uses select field).
Select Field
Select fields are recommended for variant groups with many options and/or that don't need option specific styling.
Add Custom Attributes
The following custom attributes are needed for real-time price, image, and inventory display. More info on how to add custom attributes in Webflow here.
Price - Select your price display element and add a custom attribute with the name
foxy-id
and valueprice
.Image - Select your product image element and add a custom attribute with the name
foxy-id
and valueimage
.Inventory - Select your inventory display element and add a custom attribute with the name
foxy-id
and valueinventory
.
Required Attributes
foxy-id="variant-item"
Required for each variant item. No changes needed to attribute name or value.
foxy-variant-NAME=""
For each variant group (ie: Size, Color, etc.), this attribute is needed. Replace NAME with variant group name (same format as the custom attribute used earlier) (ie: foxy-variant-color
). Set value as corresponding CMS field. Repeat for each variant group.
Optional Attributes
foxy-variant-price=""
This is the price that will be displayed on page and passed to the cart if variant combination is chosen. Replace PRICE value with corresponding CMS field.
foxy-variant-image=""
This is the image that will be displayed on page and passed to the cart if variant combination is chosen. Replace IMAGE value with corresponding CMS field.
foxy-variant-weight=""
This is the weight that will be passed to the cart if variant combination is chosen. Weight is used for shipping calculations (if needed). Replace WEIGHT value with corresponding CMS field.
foxy-variant-sku=""
This is the SKU that will be assed to the cart if variant combination is chosen. Replace SKU value with corresponding CMS field.
foxy-variant-inventory=""
When inventory control is enabled, this value will determine if the variant combination is available and allowed quantity that can be added to cart. Replace INVENTORY value with corresponding CMS field.
Style Attributes
It's possible to dynamically style radio buttons using CMS data and any CSS property. For example, each color option can have a different background color, border color, and icon.
Style attribute names consist of three parts, each joined with a hyphen:
Required prefix: foxy-variant
Variant group name: color
CSS property: background-color
The above would look like this: foxy-variant-color-background-color=""
Set the value to corresponding CMS field. This would set the background color of this specific radio button to whatever color is set in CMS.
Custom Attributes
It's possible to pass custom variant specific values to the cart as well. Custom attribute names consist of two parts, each joined with a hyphen:
Required prefix: foxy-variant
Attribute name: ie: description
The above would look like this: foxy-variant-description=""
Set the value to corresponding CMS field. In your add to cart form HTML Embed element, be sure to add a corresponding hidden input with the same name.
Add Variants Snippet
The variants snippet handles all the needed logic to make the variants functionality work. In your product detail page settings, specifically in the closing </body> section, copy/paste the snippet below (after any existing code):
<!-- FOXY VARIANTS -->
<script src="https://cdn-js.foxy.io/website-helpers@1/foxy-variants.js"></script>
<script>
(() => {
const config = {
sortBy: "",
sortOrder: "",
priceDisplay: "low-high",
pricePrecision: "2",
defaultLocale: "en-US",
defaultCurrency: "USD",
inventoryControl: false,
inventoryDefaultLabel: "Please choose options",
selectUnavailableLabel: "Unavailable",
multiCurrency: false,
multilingual: false,
addonsConfig: null,
};
const variants = Foxy.setVariantConfig(config);
variants.init();
})();
</script>
Configure Variants Snippet
The default snippet configuration will work for most, but each option can be modified as needed. Please refer to the chart below for info on what each option does and supported values:
sortBy
Controls what options for each variant group should be sorted by.
"" (default) - Sorts by order items were added in CMS multi-reference field
"label" - Sorts by option label
"price" - Sorts by option price
sortOrder
Controls order options for each variant group should be listed in.
"" (default) - Sorts by order items were added in CMS multi-reference field
"ascending" - Ascending order
"descending" - Descending order
priceDisplay
Controls how pricing is displayed for your price display element on page load (when no variants have been chosen yet).
"low-high" (default) - Displays a low to high price range
"low" - Displays lowest price
"high" - Displays highest price
pricePrecision
Controls the number of decimal places.
Defaults to "2". Supports any integer number value.
defaultLocale
Controls language and regional preference.
Supports any standard language code (ie: en-US)
defaultCurrency
Controls currency used on page.
Supports any valid three-letter ISO 4217 currency code (ie: "USD", "EUR", "GBP")
inventoryControl
Controls whether variant inventory count should be considered.
"true" - Only in-stock variant combinations can be added to cart and purchased
"false" - Inventory count will be ignored and all variant combinations can be added to cart and purchased
inventoryDefaultLabel
When inventory control is enabled and an element is used to display available inventory, this is the text that will be displayed on page load (before customer configures variant options).
selectUnavailableLabel
When a specific option is unavailable, this is the text that will be displayed next to the option label in select fields.
multiCurrency
If you need multi-currency, please contact us for more info. Functionality is available, but documentation is coming soon.
multilingual
If you need multilingual, please contact us for more info. Functionality is available, but documentation is coming soon.
addonsConfig
This setting is related to multi-currency and multilingual.