Documentation

Disable (grey Out) Out-of-stock Swatches

If you have less variations than the AJAX variation threshold, you can grey out or disable out-of-stock attribute options. There are 2 ways to do this:

Hide out of stock products

The first option is to toggle a simple setting in WooCommerce.

  1. Navigate to WooCommerce > Settings > Products > Inventory
  2. Ensure “Hide out of stock items from the catalog” is checked.

Note: This will grey out/disable the swatch options, but it will also hide any out of stock products throughout your store.

Filter variation visibility

The second option is to add a filter to your theme’s functions.php file that only affects variations.

/**
 * Disable out of stock variations
 *
 * @param bool $active
 * @param WC_Product_Variation $variation
 *
 * @return Boolean
 */
function iconic_variation_is_active( $active, $variation ) {
	if( ! $variation->is_in_stock() ) {
		return false;
	}

	return $active;
}

add_filter( 'woocommerce_variation_is_active', 'iconic_variation_is_active', 10, 2 );

This will disable swatches when a variation is out of stock, but keep out of stock products throughout the store visible (if the checkbox is the previous step is left unchecked).

Are you using WooCommerce Attribute Swatches yet?

Start your 14-day free trial right now and get instant access to the features described in this article.

or learn more

Was this helpful?

Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.

WooCommerce Attribute Swatches

WooCommerce Attribute Swatches

Not got the plugin yet? Get instant access right now, free for 14 days.

or learn more

Still need help?

If you haven't found what you're looking for in our documentation, please contact support.

Get Support