Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created June 25, 2025 08:43
Show Gist options
  • Select an option

  • Save shameemreza/dcb964e6ce4e52e1304a332756c66fd6 to your computer and use it in GitHub Desktop.

Select an option

Save shameemreza/dcb964e6ce4e52e1304a332756c66fd6 to your computer and use it in GitHub Desktop.
Hides disabled WooCommerce variations (unpublished) even when variable product attributes use "Any." Prevents unavailable variations from showing on the frontend.
/**
* Force hide disabled variations even when "Any" is used
*/
add_filter('woocommerce_variation_is_visible', function($visible, $variation_id) {
$variation = wc_get_product($variation_id);
// If variation is disabled (not published), hide it regardless of "Any" settings
if ($variation && $variation->get_status() !== 'publish') {
return false;
}
return $visible;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment