Search...
addProductMediaToChoices( )
Links media items that are already associated with a specific product to a choice within the same product.
Description
Media items can only be set for choices within one option at a time - e.g., if you set media items for some or all of the choices within the Colors option (blue, green, and red), you won't be able to also assign media items to choices within the Size option (S, M, and L).
To remove all existing media items, call the Remove Product Media From Choices endpoint.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function addProductMediaToChoices(_id: string, media: Array<MediaAssignmentToChoice>): Promise<void>
addProductMediaToChoices Parameters
NAME
TYPE
DESCRIPTION
_id
string
Product ID.
media
Array<
MediaAssignmentToChoice
>Product media items and the choices to add the media to.
Returns
Return Type:
Promise<
void
>Was this helpful?
addProductMediaToChoices example
Copy Code
1import { products } from 'wix-stores.v2';23 async function addProductMediaToChoices(id, media) {4 try {5 const result = await products.addProductMediaToChoices(id, media);67 return result;8 } catch (error) {9 console.error(error);10 // Handle the error11 }12 }13