Snippet to prevent users from selecting variations that are out of stock.
Check if the variation is out of stock and set it as inactive:
I ran into difficulties with this at first. It didn’t mater the priority I gave to the filter or if the callable function just returned false – the variation that was out of stock was still showing.
This modifies the ajax variation threshold. So, instead of fetching data via Ajax this will keep it as inline json. If the threshold isn’t increased, our custom functionality won’t work. The threshold may vary from site to site depending on the number of variations a product may have.