removeProductMedia( )
Removes media items by ID from a product.
Description
The removeProductMedia()
function returns a Promise that resolves when the
media items with the given IDs are removed from a product with a given ID.
You can remove multiple media items from a product at one time by delimiting the list of products
with commas.
If you do not specify any media IDs, all media items are removed from the product.
Removing media items from a product does not delete the media from the site.
Syntax
function removeProductMedia(productId: string, media: Array<Media>): Promise<void>
removeProductMedia Parameters
NAME
TYPE
DESCRIPTION
ID of the product from which to remove media items.
Sources of media items already uploaded to the Wix site. If no media
is specified, all media items are removed from the product.
Returns
Fulfilled - When the media items are removed from the product. Rejected - Error message.
Return Type:
Related Content:
Was this helpful?
Remove all media items from a product
1/*******************************2 * Backend code - products.jsw *3 *******************************/45import wixStoresBackend from 'wix-stores-backend';67export function removeProductMedia(productId, media) {8 return wixStoresBackend.removeProductMedia(productId, media);9}1011/*************12 * Page code *13 *************/14import wixData from 'wix-data';15import { removeProductMedia } from 'backend/products';1617// ...1819const productName = ...; // get name of product2021wixData.query("Stores/Products")22 .eq("name", productName)23 .find()24 .then((results) => {25 if (results.items.length > 0) {26 const productId = results.items[0]._id;27 removeProductMedia(productId) // not passing media will remove all media from product28 .then(() => {29 // all media items removed from the product30 })31 .catch((error) => {32 // media items not removed from the product33 });34 }35 });