less than a minute read • Updated 3 months ago
Manage product variants with Webflow CMS (Advanced)
Use Webstudio to manage and display variant groups, options, available inventory, and more.
Note
This article assumes you have already set up a CMS Connection and add to cart forms in Webstudio. More information here.
Overview
By using Foxy and Webstudio with your CMS you can bring ecommerce functionality to your Webstudio site.
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 (Weglot, and other services)
Multi-currency
Objectives
In this article, we'll accomplish the following:
Create a product variants data collection in your page
Reference product variants from your CMS
Set up variant group elements, select fields, and radio buttons in add to cart form
Configure variant snippet settings
Demo
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.
Price - Select your price display element and add a custom HTML attribute with the name
foxy-idand valueprice.Image - Select your product image element and add a custom HTML attribute with the name
foxy-idand valueimage.Inventory - Select your inventory display element and add a custom HTML attribute with the name
foxy-idand 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 (after the rest of the elements), copy/paste the snippet below into an HTML embed:
<!-- FOXY VARIANTS -->
<script src="https://cdn-js.foxy.io/website-helpers@1/foxy-variants.js"></script>
<script defer>
(() => {
const config = {
sortBy: "",
sortOrder: "",
defaultLocale: "en-US",
defaultCurrency: "USD",
priceDisplay: "low",
inventoryDefaultLabel: "Please choose options",
selectUnavailableLabel: "Unavailable",
inventoryControl: false,
multiCurrency: false,
multilingual: false,
addonsConfig: null,
forceReinit: true,
};
Foxy.variantsAutoInit(config);
})();
</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.