Theres now an easier, simpler way to check if Additional Cost products are in stock and stop the customer from being able to add the product to the cart if its out of stock! Adding w3-error-on-outofstock to the forms class will check the additional costs stock when added to the cart.
We will need to add the class to the form on the product page. Navigate to your product.liquid file and open in the previewer.
Search for "form"
(If your products page does not contain the "form" then this is located in a nested file and will need to be located. See image below of an example.)
(This code contains a comment that states the location of the nested file being in the file product-template.liquid. Navigate to this file and search again for form.)
If your product form looks like the following, then add the class to the capture form_class
Or your form may look like this instead and the class will be added within the class=""
Now if the additional cost product is out of stock and the customer trys to add the product to the cart, a popup message will display alerting the customer: