/**
 * Swift: on-sale products show the old price (red, crossed out) with the
 * new sale price below it, keeping the existing BGN + EUR dual display.
 * Applies to simple products on sale. Variable products keep the current look.
 */

// Official locked BGN-per-EUR rate.
if ( ! defined( 'SWIFT_BGN_PER_EUR' ) ) {
    define( 'SWIFT_BGN_PER_EUR', 1.95583 );
}

// Render one BGN amount as "лв.X - €Y" (matches your store's existing format).
function swift_dual_amount( $bgn_amount ) {
    $bgn_html = wc_price( $bgn_amount );
    $eur      = number_format( (float) $bgn_amount / SWIFT_BGN_PER_EUR, 2, '.', '' );
    $eur_html = ''
              . '&euro;' . $eur
              . '';
    return $bgn_html . ' - ' . $eur_html;
}

// Rebuild the price HTML for simple products that are on sale.
add_filter( 'woocommerce_get_price_html', 'swift_dual_sale_price_html', 9999, 2 );
function swift_dual_sale_price_html( $price_html, $product ) {
    if ( ! ( $product instanceof WC_Product ) || ! $product->is_on_sale() ) {
        return $price_html;
    }
    $regular = $product->get_regular_price();
    $sale    = $product->get_sale_price();
    if ( '' === (string) $regular || '' === (string) $sale ) {
        return $price_html; // variable products / price ranges: leave untouched
    }
    return ''
         . '' . swift_dual_amount( $regular ) . ''
         . '' . swift_dual_amount( $sale ) . ''
         . '';
}

// Styling: old price red + crossed, new price bold underneath.
add_action( 'wp_head', 'swift_dual_sale_price_css' );
function swift_dual_sale_price_css() {
    echo '
        .swift-bgn-eur.swift-on-sale { display:inline-block; line-height:1.4; }
        .swift-bgn-eur.swift-on-sale .swift-old-price {
            display:block; color:#e60000; text-decoration:line-through;
            opacity:1; font-weight:400;
        }
        .swift-bgn-eur.swift-on-sale .swift-new-price {
            display:block; text-decoration:none; font-weight:700;
        }
    ';
}