Created
June 25, 2025 08:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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