Search...
getSelectedVariantId( )
Gets the variant ID of the selected product variant.
Description
This function is currently only available for Wix Studio sites.
The getSelectedVariantId()
function returns a Promise that is resolved when the selected product variant's ID is
retrieved.
Syntax
function getSelectedVariantId(): Promise<string>
getSelectedVariantId Parameters
This function does not take any parameters.
Returns
Fulfilled - Selected product variant ID.
Return Type:
Promise<string>
Was this helpful?
Get the selected product variant's ID
Copy Code
1$w('#myProductPage').getSelectedVariantId()2 .then((variantId) => {3 let selectedProductVariantId = variantId; // '657321df-0d8c-4634-a6b4-1fa49d194bb7'4 })5 .catch((error) => {6 console.error(error);7 });
Get the selected product variant data by
variantID
Copy Code
1import wixData from 'wix-data';23$w('#myProductPage').getSelectedVariantId()4 .then((variantId) => {5 let selectedProductVariantId = variantId; // '657321df-0d8c-4634-a6b4-1fa49d194bb7'67 if (selectedProductVariantId) {8 wixData.query('Stores/Variants')9 .eq('variantId', selectedProductVariantId)10 .find()11 .then((results) => {12 let variantData = results.items[0];13 });14 }15 })16 .catch((error) => {17 console.error(error);18 });