Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Created November 12, 2024 11:48
Show Gist options
  • Save tdmrhn/dcb4fb3da7e0ff6d7b82a90ed6db2d8b to your computer and use it in GitHub Desktop.
Save tdmrhn/dcb4fb3da7e0ff6d7b82a90ed6db2d8b to your computer and use it in GitHub Desktop.
Woo sale badge display even with only one variation
<?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