addProductMediaToChoices( )


Adds media items by ID to product options.

The addProductMediaToChoices() function returns a Promise that resolves when the adding of media (images or videos) to a product's options has started.

Method Declaration
Copy
function addProductMediaToChoices(
  productId: string,
  mediaChoices: Array<MediaChoice>,
): Promise<void>;
Method Parameters
productIdstringRequired

ID of the product with choices to which to add media items.


mediaChoicesArray<MediaChoice>Required

Product media items, and the choices to add the media to.

Note: Media must already be added to the product.

Add media items to product options
JavaScript
/******************************* * Backend code - products.jsw * *******************************/ import wixStoresBackend from 'wix-stores-backend'; export function addProductMediaToChoices(productId, mediaData) { return wixStoresBackend.addProductMediaToChoices(productId, mediaData); } /************* * Page code * *************/ import { addProductMediaToChoices } from 'backend/products'; // ... const productId = ...; // get product ID const mediaSources = ["wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"]; const option = "Color"; const choice = "Blue"; const mediaData = [{ mediaSources, option, choice }]; addProductMediaToChoices(productId, mediaData)
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?