Search.../

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
productId
string

ID of the product from which to remove media items.

media
Array<Media>

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:

Promise<void>

Was this helpful?

Remove all media items from a product

Copy Code
1/*******************************
2 * Backend code - products.jsw *
3 *******************************/
4
5import wixStoresBackend from 'wix-stores-backend';
6
7export function removeProductMedia(productId, media) {
8 return wixStoresBackend.removeProductMedia(productId, media);
9}
10
11/*************
12 * Page code *
13 *************/
14import wixData from 'wix-data';
15import { removeProductMedia } from 'backend/products';
16
17// ...
18
19const productName = ...; // get name of product
20
21wixData.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 product
28 .then(() => {
29 // all media items removed from the product
30 })
31 .catch((error) => {
32 // media items not removed from the product
33 });
34 }
35 });