Removes media items by ID from a product's options.
The removeProductMediaFromChoices()
function returns a Promise that resolves when the
products with the given IDs are removed from a product's options.
You can remove multiple media items from a product's option at one time by delimiting the list of options with commas.
Removing media items from a product option does not delete the media items from the product.
function removeProductMediaFromChoices(
productId: string,
mediaChoices: Array<MediaChoice>,
): Promise<void>;
ID of the product from whose options to remove media items.
Media items already uploaded to the Wix site, and the choices to which to upload the media. If no choices are specified, the media items are removed from all choices for the given product.
/*******************************
* Backend code - products.jsw *
*******************************/
import wixStoresBackend from "wix-stores-backend";
export function removeProductMediaFromChoices(productId, choiceIds) {
return wixStoresBackend.removeProductMediaFromChoices(productId, choiceIds);
}
/*************
* Page code *
*************/
import { removeProductMediaFromChoices } from "backend/products";
// ...
const productId = "1a11aaa3-...-111a1aaa111";
const choices = [
{
option: "Color",
choice: "Blue",
},
];
removeProductMediaFromChoices(productId, choices)
.then(() => {
// media items removed from the product choices
})
.catch((error) => {
// media items not removed from the product choices
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.