A simple, powerful and independent e-commerce platform.
Sell anything with ease.

Show out of stock variation selections as greyed out

Variations in the drop-down list all appear to be available. It’s not until one is selected that it is shown as out of stock. This code snippet disables selection of the out-of-stock options and greys them out. If your theme is not showing any difference between the disabled and enabled options you may need to also add this code to your css file:

select#pa_product-type option:disabled {
  color: #c9c9c9;
}

		/**
 * Show out of stock variation selections as greyed out
 */

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

function cc_out_of_stock_variations_show_grey($is_active, $variation) {

  if (!$variation->is_in_stock()) return false;

  return $is_active;

}
	
View Raw Code ID: 91081