Sale badge compatibility for Woostify Theme
Ensure sale badges display correctly in the Woostify theme.
// Fix sale badge shows -100% when discount is applied
add_filter('woostify_price_flash', function($final_price, $product) {
if (is_object($product) && $product->is_type(['simple', 'external', 'bundle'])) {
$discount = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', false, $product, 1, 0, 'all', true, false);
if ($discount !== false && is_array($discount) && isset($discount['initial_price']) && isset($discount['discounted_price'])) {
$percentage = round((($discount['initial_price'] - $discount['discounted_price']) / $discount['initial_price']) * 100);
if ($percentage > 0) {
$final_price = '-' . $percentage . '%';
}
}
}
return $final_price;
}, 100, 2);