Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogjunkie/9493f5831bbb6c630d73537e47080365 to your computer and use it in GitHub Desktop.
Save blogjunkie/9493f5831bbb6c630d73537e47080365 to your computer and use it in GitHub Desktop.
Grey out variations that are out of stock for WooCommerce
/**
* Disable out of stock variations
* https://github.com/woocommerce/woocommerce/blob/826af31e1e3b6e8e5fc3c1004cc517c5c5ec25b1/includes/class-wc-product-variation.php
* @return Boolean
*/
function wcbv_variation_is_active( $active, $variation ) {
if( ! $variation->is_in_stock() ) {
return false;
}
return $active;
}
add_filter( 'woocommerce_variation_is_active', 'wcbv_variation_is_active', 10, 2 );
@blogjunkie
Copy link
Author

For more control over display of out of stock variations, see:
https://pluginrepublic.com/wordpress-plugins/woocommerce-better-variations/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment