Removes products by ID from a collection.
The removeProductsFromCollection()
function returns a Promise that resolves when the
products with the given IDs are removed from a specified collection.
You can remove multiple products from a collection at one time by delimiting the list of products with commas.
If you do not specify any IDs, all products are removed from the collection.
Removing products from a collection does not delete the products from the store. See deleteProduct()
to delete a product from the store.
function removeProductsFromCollection(
collectionId: string,
productIds: Array<string>,
): Promise<void>;
ID of the collection from which to remove products.
IDs of the products to remove from the collection.
/*******************************
* Backend code - products.jsw *
*******************************/
import wixStoresBackend from 'wix-stores-backend';
export function removeProductsFromCollection(collectionId, productIds) {
return wixStoresBackend.removeProductsFromCollection(collectionId, productIds);
}
/*************
* Page code *
*************/
import { removeProductsFromCollection } from 'backend/products';
// ...
const collectionId = ... // get collection ID
const productIds = ["id1", "id2", "id3"];
removeProductsFromCollection(collectionId, productIds)
.then(() => {
// products removed from the collection
})
.catch((error) => {
// products not removed from the collection
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.