Created
November 12, 2024 11:48
-
-
Save tdmrhn/dcb4fb3da7e0ff6d7b82a90ed6db2d8b to your computer and use it in GitHub Desktop.
Woo sale badge display even with only one variation
This file contains 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
<?php | |
add_filter('woocommerce_product_is_on_sale', function ($on_sale, $product) { | |
if ($product->is_type('variable') && (is_shop() || is_product() || is_product_category() || is_product_tag())) { | |
foreach ($product->get_children() as $variation_id) { | |
$variation = wc_get_product($variation_id); | |
if ($variation->is_on_sale()) { | |
return true; | |
} | |
} | |
} | |
return $on_sale; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment