<?php if (!defined('ABSPATH')) exit; class GT_BOGO_Widgets { public static function init() { } public static function render_bogo_calculator() { global $product; echo '<div class="gtbogo-calculator-widget" style="background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 20px 0;">'; echo '<h4 style="margin: 0 0 15px 0; font-family:inherit; color:inherit;">Your savings</h4>'; echo '<div style="display: flex; gap: 15px; align-items: center;">'; echo '<label>Buy <input type="number" id="gtbogo-calc-qty" value="2" min="1" max="10" style="width: 60px; padding: 8px; border: 1px solid #ddd; border-radius: 4px;"> items</label>'; echo '<div id="gtbogo-calc-result" style="font-size: 18px; font-weight: 700; color: #ff0000;"></div>'; echo '</div>'; echo '</div>'; ?> <script> jQuery(document).ready(function($) { function calculateSavings() { var qty = parseInt($('#gtbogo-calc-qty').val()); var price = <?php echo esc_js( $product->get_price() ); ?>; var normalTotal = qty * price; var bogoSets = Math.floor(qty / 2); var bogoTotal = (qty - bogoSets) * price + (bogoSets * price * 0.5); var savings = normalTotal - bogoTotal; $('#gtbogo-calc-result').html('Save $' + savings.toFixed(2) + '!'); } $('#gtbogo-calc-qty').on('input', calculateSavings); calculateSavings(); }); </script> <?php } public static function render_savings_visualizer() { echo '<div class="gtbogo-savings-viz" style="background: linear-gradient(135deg, #ff0000 0%, #cc0000 100%); color: #fff; padding: 15px; border-radius: 8px; margin: 15px 0; text-align: center;">'; echo '<div style="font-size: 24px; font-weight: 700; margin-bottom: 5px;">BUY 1 GET 1 AT 50% OFF</div>'; echo '<div style="font-size: 14px; opacity: 0.95;">Deal applied automatically at checkout</div>'; echo '</div>'; } }