How to delete a product when inventory reaches 0 for another product

I have 2 digital products available on my site, lets call them ‘product a’ and ‘product b’. When the inventory for ‘product a’ reaches zero I want ‘product b’ also to be shown as out of stock or removed from the website. From my research I’ve found that I will have to use the getProductOptionsAvailability or onInventoryItemUpdatedfor ‘product a’ and either deleteProduct or removeProductsFromCollection or InventoryItem for ‘product b’.

Yes, because you probably use WixStores, here you will find all the OPTIONS which you can use…
https://www.wix.com/corvid/reference/wix-stores.html

Hey, I did have a look at that page actually before posting my question. Would you be able to give any insight as to which function to use and how to best use it as I am not very good with coding

Hello again,

sorry i think i can’t really help you because i suggest you will use “Wix-Stores”.
I am not very familiar with this APP, because i do not use it.

This could be perhaps the right one, but really not sure…

import wixStores from 'wix-stores';


let productId = // get product ID
let choices = {
  "Size": "Large"
};

wixStores.getProductOptionsAvailability(productId, choices)
  .then( (availability) => {
      let available = availability.availableForPurchase;  // false
      let options = availability.productOptions;          // see below
      let mainMedia = availability.mainMedia;
      let mediaItems = availability.mediaItems;
      let selectedVariant = availability.selectedVariant; // null
  } )
  .catch( (error) => {
    console.log(error);
  } );

/*
 * options:
 *
 * "Size":{
 *   "optionType":"drop_down",
 *   "name":"Size",
 *   "choices":[
 *     {
 *       "value":"Small",
 *       "description":"Small",
 *       "inStock":true,
 *       "visible":true
 *     },
 *     {
 *       "value":"Large",
 *       "description":"Large",
 *       "inStock":true,
 *       "visible":true
 *     }
 *   ]
 * },
 * "Color":{
 *   "optionType":"color",
 *   "name":"Color",
 *   "choices":[
 *     {
 *       "value":"rgb(0, 128, 0)",
 *       "description":"green",
 *       "inStock":true,
 *       "visible":true
 *     },
 *     {
 *       "value":"rgb(255, 0, 0)",
 *       "description":"red",
 *       "inStock":true,
 *       "visible":true
 *     }
 *   ]
 * }
 */