<?php if (!defined('ABSPATH')) exit; class GT_BOGO_Customer_Portal { public static function init() { add_action('woocommerce_account_dashboard', array(__CLASS__, 'render_portal'), 5); } public static function render_portal() { $user_id = get_current_user_id(); if (!$user_id) return; $bogo_orders = self::get_bogo_orders($user_id); $total_saved = self::calculate_total_savings($user_id); echo '<div class="gtbogo-customer-portal" style="margin-bottom: 30px;">'; echo '<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px;">'; echo '<div style="background: linear-gradient(135deg, #ff0000 0%, #cc0000 100%); color: #fff; padding: 25px; border-radius: 12px;">'; echo '<div style="font-size: 36px; font-weight: 700; margin-bottom: 5px;">$' . number_format($total_saved, 2) . '</div>'; echo '<div style="opacity: 0.95;">Total BOGO Savings</div>'; echo '</div>'; echo '<div style="background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%); color: #fff; padding: 25px; border-radius: 12px;">'; echo '<div style="font-size: 36px; font-weight: 700; margin-bottom: 5px;">' . count($bogo_orders) . '</div>'; echo '<div style="opacity: 0.95;">BOGO Orders</div>'; echo '</div>'; echo '</div>'; echo '<div style="background: #fff; padding: 25px; border-radius: 12px; border: 1px solid #e5e7eb;">'; echo '<h3 style="margin: 0 0 20px 0; color: #020617;">Recent History</h3>'; if (!empty($bogo_orders)) { echo '<table style="width: 100%; border-collapse: collapse;">'; echo '<thead><tr style="border-bottom: 2px solid #e5e7eb;"><th style="padding: 10px; text-align: left;">Order</th><th>Date</th><th>Saved</th></tr></thead>'; echo '<tbody>'; foreach (array_slice($bogo_orders, 0, 5) as $order) { echo '<tr style="border-bottom: 1px solid #f3f4f6;">'; echo '<td style="padding: 12px;">#' . esc_html( $order->get_order_number() ) . '</td>'; echo '<td style="padding: 12px;">' . esc_html( $order->get_date_created()->format('M j, Y') ) . '</td>'; echo '<td style="padding: 12px; color: #ff0000; font-weight: 600;">$' . number_format($order->get_discount_total(), 2) . '</td>'; echo '</tr>'; } echo '</tbody></table>'; } else { echo '<p style="color: #64748b; text-align: center; padding: 20px;">No BOGO orders yet. Start shopping to unlock deals!</p>'; } echo '</div>'; echo '</div>'; } private static function get_bogo_orders($user_id) { return wc_get_orders(array( 'customer_id' => $user_id, 'status' => array('completed', 'processing'), 'limit' => -1, 'meta_query' => array( array( 'key' => '_gtbogo_applied', 'value' => '1' ) ) )); } private static function calculate_total_savings($user_id) { $orders = self::get_bogo_orders($user_id); $total = 0; foreach ($orders as $order) { $total += $order->get_discount_total(); } return $total; } } GT_BOGO_Customer_Portal::init();