Disable out of stock variations in WooCommerce

Posted: 8 months ago


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:

PHP
functions.php

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.

PHP
functions.php

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.