/**
Theme Name: TGS Child
Author: Brainstorm Force
Author URI: http://wpastra.com/about/
Description: Astra is the fastest, fully customizable & beautiful theme suitable for blogs, personal portfolios and business websites. It is very lightweight (less than 50KB on frontend) and offers unparalleled speed. Built with SEO in mind, Astra comes with schema.org code integrated so search engines will love your site. Astra offers plenty of sidebar options and widget areas giving you a full control for customizations. Furthermore, we have included special features and templates so feel free to choose any of your favorite page builder plugin to create pages flexibly. Some of the other features: # WooCommerce Ready # Responsive # Compatible with major plugins # Translation Ready # Extendible with premium addons # Regularly updated # Designed, Developed, Maintained & Supported by Brainstorm Force. Looking for a perfect base theme? Look no further. Astra is fast, fully customizable and beautiful theme!
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: tgs-child
Template: astra



<?php
// Register AJAX actions
add_action('wp_ajax_booking_form_submit', 'booking_form_submit');
add_action('wp_ajax_nopriv_booking_form_submit', 'booking_form_submit');

function booking_form_submit() {
    // Ensure we always return JSON
    header('Content-Type: application/json');

    try {
        // Check required fields
        $reg_id = isset($_POST['form_fields']['reg_id_1']) ? sanitize_text_field($_POST['form_fields']['reg_id_1']) : '';
        $email = isset($_POST['form_fields']['user1_email']) ? sanitize_email($_POST['form_fields']['user1_email']) : '';
        $price = isset($_POST['form_fields']['price']) ? floatval($_POST['form_fields']['price']) : 0;

        if(empty($reg_id) || empty($email) || $price <= 0) {
            wp_send_json([
                'success' => false,
                'data' => ['message' => 'Please fill all required fields and ensure total is valid.']
            ]);
        }

        // Create WooCommerce product in cart (example: using product ID 123)
        $product_id = 4655; // <-- Enter your product ID here
        WC()->cart->empty_cart();
        WC()->cart->add_to_cart($product_id, 1);

        // Optionally, set custom price
        if($price > 0) {
            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
                if( $cart_item['product_id'] == $product_id ) {
                    $cart_item['data']->set_price($price);
                }
            }
        }

        // Return success with redirect URL
        wp_send_json([
            'success' => true,
            'data' => [
                'redirect_url' => wc_get_checkout_url()
            ]
        ]);

    } catch(Exception $e) {
        wp_send_json([
            'success' => false,
            'data' => ['message' => 'Server error: ' . $e->getMessage()]
        ]);
    }

    wp_die();
}

?>


<?php
/**
 * Complete WooCommerce Integration for Hotel Booking Form
 * With Getepay payment gateway integration and auto-completion
 * Add this to your theme's functions.php
 

// Enable debugging
if (!defined('WP_DEBUG')) {
    define('WP_DEBUG', false);
    define('WP_DEBUG_LOG', false);
    define('WP_DEBUG_DISPLAY', false);
}

// Force guest checkout
add_filter('woocommerce_checkout_customer_id', 'force_guest_checkout');
function force_guest_checkout($customer_id) {
    if (isset($_GET['pay_for_order']) && isset($_GET['key'])) {
        return 0;
    }
    return $customer_id;
}

// Allow guest checkout
add_filter('woocommerce_enable_guest_checkout', '__return_true');

// Create WooCommerce order from Elementor form with validation
add_action('wp_ajax_create_booking_order', 'create_booking_order');
add_action('wp_ajax_nopriv_create_booking_order', 'create_booking_order');

function create_booking_order() {
    check_ajax_referer('booking_nonce', 'nonce');
    
    $data = $_POST['form_data'];
    
    // Server-side validation
    $required_fields = array(
        'reg_id_1' => 'Registration ID',
        'field_d5bd7e6' => 'Title',
        'user1_first_name' => 'First Name',
        'user1_last_name' => 'Last Name',
        'user1_phone' => 'Phone',
        'user1_email' => 'Email',
        'field_3960aea' => 'Chapter',
        'hotelSelect' => 'Hotel',
        'checkin' => 'Check-in',
        'checkout' => 'Check-out',
        'occupancy' => 'Occupancy',
        'product_id' => 'Product ID',
        'price' => 'Price'
    );
    
    $errors = array();
    
    foreach ($required_fields as $field => $label) {
        if (empty($data[$field]) || trim($data[$field]) === '' || strpos($data[$field], 'Select') === 0) {
            $errors[] = $label . ' is required';
        }
    }
    
    // Validate names
    if (!empty($data['user1_first_name'])) {
        if (!preg_match('/^[A-Za-z\s]{2,}$/', trim($data['user1_first_name']))) {
            $errors[] = 'First Name must contain only letters and be at least 2 characters';
        }
    }
    
    if (!empty($data['user1_last_name'])) {
        if (!preg_match('/^[A-Za-z\s]{2,}$/', trim($data['user1_last_name']))) {
            $errors[] = 'Last Name must contain only letters and be at least 2 characters';
        }
    }
    
    // Validate email
    if (!empty($data['user1_email']) && !is_email($data['user1_email'])) {
        $errors[] = 'Invalid email address';
    }
    
    // Validate phone
    if (!empty($data['user1_phone'])) {
        $phone_digits = preg_replace('/\D/', '', $data['user1_phone']);
        if (strlen($phone_digits) < 10) {
            $errors[] = 'Invalid phone number';
        }
    }
    
    // Validate dates
    if (!empty($data['checkin']) && !empty($data['checkout'])) {
        $checkin = strtotime($data['checkin']);
        $checkout = strtotime($data['checkout']);
        if ($checkout <= $checkin) {
            $errors[] = 'Check-out must be after check-in';
        }
    }
    
    $total_with_tax = floatval(str_replace(['₹', ',', ' '], '', $data['price']));
    if ($total_with_tax <= 0) {
        $errors[] = 'Invalid price';
    }
    
    if (!empty($errors)) {
        wp_send_json_error(array('message' => implode(', ', $errors)));
        return;
    }
    
    $product_id = intval($data['product_id']);
    $base_amount = $total_with_tax / 1.18;
    $tax_amount = $total_with_tax - $base_amount;
    
    add_filter('woocommerce_order_is_vat_exempt', '__return_true');
    
    try {
        $order = wc_create_order();
        if (!$order) throw new Exception('Failed to create order');
        
        $product = wc_get_product($product_id);
        if (!$product) throw new Exception('Invalid product');
        
        $order->add_product($product, 1, array('subtotal' => $base_amount, 'total' => $base_amount));
        
        $fee = new WC_Order_Item_Fee();
        $fee->set_name('GST (18%)');
        $fee->set_amount($tax_amount);
        $fee->set_tax_status('none');
        $fee->set_total($tax_amount);
        $order->add_item($fee);
        
        $order->update_meta_data('_booking_base_amount', $base_amount);
        $order->update_meta_data('_booking_tax_amount', $tax_amount);
        $order->update_meta_data('_booking_total_amount', $total_with_tax);
        $order->update_meta_data('_booking_reg_id', sanitize_text_field($data['reg_id_1']));
        $order->update_meta_data('_booking_title', sanitize_text_field($data['field_d5bd7e6']));
        $order->update_meta_data('_booking_guest_name', sanitize_text_field($data['user1_first_name'] . ' ' . $data['user1_last_name']));
        $order->update_meta_data('_booking_phone', sanitize_text_field($data['user1_phone']));
        $order->update_meta_data('_booking_email', sanitize_email($data['user1_email']));
        $order->update_meta_data('_booking_chapter', sanitize_text_field($data['field_3960aea']));
        $order->update_meta_data('_booking_hotel', sanitize_text_field($data['hotelSelect']));
        $order->update_meta_data('_booking_checkin', sanitize_text_field($data['checkin']));
        $order->update_meta_data('_booking_checkout', sanitize_text_field($data['checkout']));
        $order->update_meta_data('_booking_occupancy', sanitize_text_field($data['occupancy']));
        
        if (!empty($data['reg_id_2'])) {
            $order->update_meta_data('_booking_second_guest_reg_id', sanitize_text_field($data['reg_id_2']));
            $order->update_meta_data('_booking_second_guest_title', sanitize_text_field($data['field_d96aed5']));
            $order->update_meta_data('_booking_second_guest_name', sanitize_text_field($data['Guest_First_Name'] . ' ' . $data['Guest_Last_Name']));
        }
        
        if (!empty($data['field_8a1648d'])) {
            $order->update_meta_data('_billing_company', sanitize_text_field($data['field_8a1648d']));
            $order->set_billing_company(sanitize_text_field($data['field_8a1648d']));
        }
        if (!empty($data['field_547e3b2'])) {
            $order->update_meta_data('_billing_gstin', sanitize_text_field($data['field_547e3b2']));
        }
        
        $order->set_billing_email(sanitize_email($data['user1_email']));
        $order->set_billing_phone(sanitize_text_field($data['user1_phone']));
        $order->set_billing_first_name(sanitize_text_field($data['user1_first_name']));
        $order->set_billing_last_name(sanitize_text_field($data['user1_last_name']));
        $order->set_customer_id(0);
        $order->set_status('pending');
        $order->set_created_via('booking_form');
        $order->calculate_totals();
        
        $calculated_total = $order->get_total();
        if (abs($calculated_total - $total_with_tax) > 0.01) {
            $order->set_total($total_with_tax);
        }
        
        $order->save();
        
        remove_filter('woocommerce_order_is_vat_exempt', '__return_true');
        
        error_log('Booking order created: #' . $order->get_id());
        
        $payment_url = $order->get_checkout_payment_url(false);
        
        wp_send_json_success(array(
            'order_id' => $order->get_id(),
            'checkout_url' => $payment_url
        ));
        
    } catch (Exception $e) {
        error_log('Booking Order Creation Error: ' . $e->getMessage());
        wp_send_json_error(array('message' => 'Failed to create booking. Please try again.'));
    }
}

// ========== GETEPAY PAYMENT GATEWAY INTEGRATION ==========

// Getepay API callback handler
add_action('woocommerce_api_wc_getepay', 'handle_getepay_booking_callback');
function handle_getepay_booking_callback() {
    $order_id = isset($_REQUEST['order_id']) ? sanitize_text_field($_REQUEST['order_id']) : '';
    
    if (!$order_id) {
        $order_id = isset($_REQUEST['txnid']) ? sanitize_text_field($_REQUEST['txnid']) : '';
    }
    
    error_log('Getepay Callback - Order ID: ' . $order_id . ', Request: ' . print_r($_REQUEST, true));
    
    if ($order_id) {
        $order = wc_get_order($order_id);
        
        if ($order && $order->get_meta('_booking_reg_id')) {
            $status = isset($_REQUEST['status']) ? strtolower(sanitize_text_field($_REQUEST['status'])) : '';
            $txnid = isset($_REQUEST['transaction_id']) ? sanitize_text_field($_REQUEST['transaction_id']) : '';
            
            if (in_array($status, array('success', 'completed', 'paid'))) {
                $order->payment_complete($txnid);
                $order->set_status('completed');
                $order->add_order_note('Getepay payment successful. Transaction ID: ' . $txnid);
                $order->save();
                
                error_log('Booking order #' . $order_id . ' completed via Getepay callback');
            }
        }
    }
}

// Complete order on return from Getepay
add_action('woocommerce_thankyou', 'complete_getepay_booking_order', 1, 1);
function complete_getepay_booking_order($order_id) {
    if (!$order_id) return;
    
    $order = wc_get_order($order_id);
    if (!$order || !$order->get_meta('_booking_reg_id')) return;
    
    $payment_method = $order->get_payment_method();
    
    if (strpos($payment_method, 'getepay') !== false || strpos($payment_method, 'gateway') !== false) {
        
        $getepay_status = isset($_GET['status']) ? strtolower(sanitize_text_field($_GET['status'])) : '';
        $getepay_txnid = isset($_GET['txnid']) ? sanitize_text_field($_GET['txnid']) : '';
        $getepay_transaction_id = isset($_GET['transaction_id']) ? sanitize_text_field($_GET['transaction_id']) : '';
        
        error_log('Getepay Return - Status: ' . $getepay_status . ', TxnID: ' . $getepay_txnid . ', Order: ' . $order_id);
        
        if (in_array($getepay_status, array('success', 'completed', 'paid')) || !empty($getepay_txnid) || !empty($getepay_transaction_id)) {
            
            $transaction_id = $getepay_transaction_id ? $getepay_transaction_id : $getepay_txnid;
            
            if ($transaction_id) {
                $order->set_transaction_id($transaction_id);
            }
            
            $order->payment_complete($transaction_id);
            $order->set_status('completed');
            $order->add_order_note('Booking confirmed via Getepay. Transaction ID: ' . $transaction_id);
            $order->save();
            
            error_log('Booking order #' . $order_id . ' completed on return from Getepay');
        }
    }
}

// Force completion for paid orders
add_action('template_redirect', 'auto_complete_paid_booking_orders');
function auto_complete_paid_booking_orders() {
    if (isset($_GET['order_id']) && isset($_GET['key'])) {
        $order_id = intval($_GET['order_id']);
        $order = wc_get_order($order_id);
        
        if ($order && $order->get_meta('_booking_reg_id') && $order->has_status('pending')) {
            
            // Check if payment was made
            if ($order->get_transaction_id() || $order->get_date_paid()) {
                $order->set_status('completed');
                $order->add_order_note('Auto-completed: Payment detected.');
                $order->save();
                
                error_log('Auto-completed booking order #' . $order_id);
            }
        }
    }
}

// Webhook endpoint for Getepay
add_action('rest_api_init', 'register_getepay_webhook_endpoint');
function register_getepay_webhook_endpoint() {
    register_rest_route('booking/v1', '/getepay-webhook', array(
        'methods' => 'POST',
        'callback' => 'handle_getepay_webhook',
        'permission_callback' => '__return_true'
    ));
}

function handle_getepay_webhook($request) {
    $params = $request->get_params();
    
    error_log('Getepay Webhook: ' . print_r($params, true));
    
    $order_id = isset($params['order_id']) ? $params['order_id'] : '';
    $status = isset($params['status']) ? strtolower($params['status']) : '';
    $txnid = isset($params['txnid']) ? $params['txnid'] : '';
    
    if ($order_id && in_array($status, array('success', 'completed', 'paid'))) {
        $order = wc_get_order($order_id);
        
        if ($order && $order->get_meta('_booking_reg_id')) {
            $order->payment_complete($txnid);
            $order->set_status('completed');
            $order->add_order_note('Webhook: Payment confirmed. TxnID: ' . $txnid);
            $order->save();
            
            return new WP_REST_Response(array('status' => 'success'), 200);
        }
    }
    
    return new WP_REST_Response(array('status' => 'failed'), 400);
}

// Log order status changes
add_action('woocommerce_order_status_changed', 'log_booking_order_status_change', 10, 4);
function log_booking_order_status_change($order_id, $old_status, $new_status, $order) {
    if ($order->get_meta('_booking_reg_id')) {
        error_log("Booking Order #{$order_id}: {$old_status} → {$new_status}");
    }
}

// Force complete virtual orders
add_filter('woocommerce_payment_complete_order_status', 'auto_complete_booking_orders', 10, 3);
function auto_complete_booking_orders($status, $order_id, $order) {
    if (!$order) {
        $order = wc_get_order($order_id);
    }
    
    if ($order->get_meta('_booking_reg_id')) {
        return 'completed';
    }
    
    return $status;
}

// Manual completion helper (visit: yourdomain.com/?complete_bookings=yes)
add_action('template_redirect', 'complete_pending_bookings_manually');
function complete_pending_bookings_manually() {
    if (isset($_GET['complete_bookings']) && $_GET['complete_bookings'] === 'yes') {
        
        if (!current_user_can('manage_woocommerce')) {
            wp_die('Unauthorized');
        }
        
        $args = array(
            'status' => 'pending',
            'limit' => -1,
            'meta_key' => '_booking_reg_id',
            'meta_compare' => 'EXISTS'
        );
        
        $orders = wc_get_orders($args);
        $completed = 0;
        
        foreach ($orders as $order) {
            $order->set_status('completed');
            $order->add_order_note('Manually completed via bulk action.');
            $order->save();
            $completed++;
        }
        
        echo "<h2>Completed {$completed} booking orders.</h2>";
        echo '<a href="' . admin_url('edit.php?post_type=shop_order') . '">View Orders</a>';
        exit;
    }
}

// ========== CHECKOUT CUSTOMIZATION ==========

add_filter('woocommerce_order_get_total', 'ensure_correct_payment_total', 10, 2);
function ensure_correct_payment_total($total, $order) {
    if ($order->get_meta('_booking_reg_id') && $order->has_status(array('pending', 'on-hold'))) {
        $booking_total = $order->get_meta('_booking_total_amount');
        if ($booking_total && $booking_total > 0) {
            return $booking_total;
        }
    }
    return $total;
}

add_action('woocommerce_before_pay_action', 'verify_order_total_before_payment', 1);
function verify_order_total_before_payment($order) {
    if ($order->get_meta('_booking_reg_id')) {
        $booking_total = $order->get_meta('_booking_total_amount');
        $current_total = $order->get_total();
        
        if ($booking_total && abs($current_total - $booking_total) > 0.01) {
            $order->set_total($booking_total);
            $order->save();
        }
    }
}

add_filter('woocommerce_get_order_item_totals', 'customize_order_totals_display', 10, 3);
function customize_order_totals_display($total_rows, $order, $tax_display) {
    if (is_wc_endpoint_url('order-pay') && $order->get_meta('_booking_reg_id')) {
        
        $base_amount = $order->get_meta('_booking_base_amount');
        $tax_amount = $order->get_meta('_booking_tax_amount');
        $total_amount = $order->get_meta('_booking_total_amount');
        
        if (!$base_amount) {
            $total_amount = $order->get_total();
            $base_amount = $total_amount / 1.18;
            $tax_amount = $total_amount - $base_amount;
        }
        
        $total_rows = array();
        
        $total_rows['base_fare'] = array(
            'label' => 'Base Fare:',
            'value' => wc_price($base_amount)
        );
        
        $total_rows['gst'] = array(
            'label' => 'GST (18%):',
            'value' => wc_price($tax_amount)
        );
        
        $total_rows['order_total'] = array(
            'label' => '<strong style="font-size:18px;">Total:</strong>',
            'value' => '<strong style="font-size:18px; color:#c00;">' . wc_price($total_amount) . '</strong>'
        );
    }
    
    return $total_rows;
}

add_action('woocommerce_before_pay_action', 'show_payment_status_message', 20);
function show_payment_status_message($order) {
    if (!$order->get_meta('_booking_reg_id')) return;
    
    $order_status = $order->get_status();
    
    if ($order_status === 'pending') {
        echo '<div class="woocommerce-info" style="margin:20px 0; padding:15px; background:#e7f7ff; border-left:4px solid #2196F3;">';
        echo '<strong>⏳ Payment Pending</strong><br>Your booking is reserved. Please complete payment.';
        echo '</div>';
    } elseif ($order_status === 'failed') {
        echo '<div class="woocommerce-error" style="margin:20px 0; padding:15px; background:#fff3cd; border-left:4px solid #ffc107;">';
        echo '<strong>⚠️ Payment Failed</strong><br>Please try again.';
        echo '</div>';
    } elseif ($order_status === 'cancelled') {
        echo '<div class="woocommerce-error" style="margin:20px 0; padding:15px; background:#f8d7da; border-left:4px solid #dc3545;">';
        echo '<strong>❌ Payment Cancelled</strong><br>Please complete payment to confirm.';
        echo '</div>';
    }
}

add_action('woocommerce_before_pay_action', 'show_booking_details_on_payment', 5);
function show_booking_details_on_payment($order) {
    $reg_id = $order->get_meta('_booking_reg_id');
    
    if ($reg_id) {
        echo '<div class="woocommerce-info booking-summary" style="margin:20px 0; padding:20px; background:#f7f7f7; border-left:4px solid #c00;">';
        echo '<h3 style="margin-top:0;">Your Booking Details</h3>';
        echo '<table style="width:100%; line-height:1.8;">';
        echo '<tr><td style="width:40%;"><strong>Registration ID:</strong></td><td>' . esc_html($reg_id) . '</td></tr>';
        echo '<tr><td><strong>Guest Name:</strong></td><td>' . esc_html($order->get_meta('_booking_guest_name')) . '</td></tr>';
        echo '<tr><td><strong>Hotel:</strong></td><td>' . esc_html($order->get_meta('_booking_hotel')) . '</td></tr>';
        echo '<tr><td><strong>Check-in:</strong></td><td>' . esc_html($order->get_meta('_booking_checkin')) . '</td></tr>';
        echo '<tr><td><strong>Check-out:</strong></td><td>' . esc_html($order->get_meta('_booking_checkout')) . '</td></tr>';
        echo '<tr><td><strong>Occupancy:</strong></td><td>' . esc_html($order->get_meta('_booking_occupancy')) . '</td></tr>';
        
        if ($order->get_meta('_booking_second_guest_name')) {
            echo '<tr><td><strong>Second Guest:</strong></td><td>' . esc_html($order->get_meta('_booking_second_guest_name')) . '</td></tr>';
        }
        
        echo '</table></div>';
    }
}

add_action('woocommerce_thankyou', 'display_booking_confirmation', 10, 1);
function display_booking_confirmation($order_id) {
    $order = wc_get_order($order_id);
    
    if (!$order->is_paid() && !$order->has_status('completed')) {
        return;
    }
    
    $reg_id = $order->get_meta('_booking_reg_id');
    
    if ($reg_id) {
        $base_amount = $order->get_meta('_booking_base_amount');
        $tax_amount = $order->get_meta('_booking_tax_amount');
        $total_amount = $order->get_meta('_booking_total_amount');
        
        if (!$base_amount) {
            $total_amount = $order->get_total();
            $base_amount = $total_amount / 1.18;
            $tax_amount = $total_amount - $base_amount;
        }
        
        echo '<div class="booking-confirmation" style="margin:20px 0; padding:20px; background:#f0f8f0; border:2px solid #4caf50; border-radius:5px;">';
        echo '<h2 style="color:#4caf50; margin-top:0;">✓ Hotel Booking Confirmed!</h2>';
        echo '<div style="line-height:1.8;">';
        echo '<p><strong>Registration ID:</strong> ' . esc_html($reg_id) . '</p>';
        echo '<p><strong>Guest Name:</strong> ' . esc_html($order->get_meta('_booking_guest_name')) . '</p>';
        echo '<p><strong>Email:</strong> ' . esc_html($order->get_meta('_booking_email')) . '</p>';
        echo '<p><strong>Phone:</strong> ' . esc_html($order->get_meta('_booking_phone')) . '</p>';
        echo '<p><strong>Hotel:</strong> ' . esc_html($order->get_meta('_booking_hotel')) . '</p>';
        echo '<p><strong>Chapter:</strong> ' . esc_html($order->get_meta('_booking_chapter')) . '</p>';
        echo '<p><strong>Check-in:</strong> ' . esc_html($order->get_meta('_booking_checkin')) . '</p>';
        echo '<p><strong>Check-out:</strong> ' . esc_html($order->get_meta('_booking_checkout')) . '</p>';
        echo '<p><strong>Occupancy:</strong> ' . esc_html($order->get_meta('_booking_occupancy')) . '</p>';
        
        if ($order->get_meta('_booking_second_guest_name')) {
            echo '<p><strong>Second Guest:</strong> ' . esc_html($order->get_meta('_booking_second_guest_name')) . '</p>';
        }
        
        echo '<hr style="margin:15px 0; border:none; border-top:1px solid #4caf50;">';
        echo '<h3 style="color:#333;">Payment Details</h3>';
        echo '<p><strong>Base Fare:</strong> ₹' . number_format($base_amount, 2) . '</p>';
        echo '<p><strong>GST (18%):</strong> ₹' . number_format($tax_amount, 2) . '</p>';
        echo '<p style="font-size:20px; margin-top:10px;"><strong>Total Paid:</strong> <span style="color:#4caf50;">₹' . number_format($total_amount, 2) . '</span></p>';
        
        echo '</div>';
        echo '<p style="margin-top:15px; color:#666; font-style:italic;">A confirmation email has been sent.</p>';
        echo '</div>';
    }
}

add_filter('woocommerce_my_account_my_orders_actions', 'remove_cancel_order_action', 10, 2);
function remove_cancel_order_action($actions, $order) {
    if ($order->get_meta('_booking_reg_id') && is_wc_endpoint_url('order-pay')) {
        unset($actions['cancel']);
    }
    return $actions;
}

add_action('wp_head', 'hide_confirmation_on_order_pay_page');
function hide_confirmation_on_order_pay_page() {
    if (is_wc_endpoint_url('order-pay')) {
        ?>
        <style>
            .woocommerce-order-pay .woocommerce-notice--success,
            .woocommerce-order-pay .woocommerce-thankyou-order-received {
                display: none !important;
            }
        </style>
        <?php
    }
}

add_filter('woocommerce_checkout_fields', 'remove_checkout_fields_for_booking_order');
function remove_checkout_fields_for_booking_order($fields) {
    if (is_wc_endpoint_url('order-pay')) {
        unset($fields['billing']['billing_country']);
        unset($fields['billing']['billing_address_1']);
        unset($fields['billing']['billing_address_2']);
        unset($fields['billing']['billing_city']);
        unset($fields['billing']['billing_state']);
        unset($fields['billing']['billing_postcode']);
    }
    return $fields;
}

add_filter('woocommerce_demo_store', 'hide_notice_on_payment_pages', 10, 2);
function hide_notice_on_payment_pages($notice, $notice_text) {
    if (is_checkout() || is_wc_endpoint_url('order-pay')) {
        return '';
    }
    return $notice;
}

add_action('wp_head', 'booking_form_validation_styles');
function booking_form_validation_styles() {
    ?>
    <style>
        #booking_form input.error, #booking_form select.error {
            border: 2px solid #dc3545 !important;
        }
        #payBtn[disabled] {
            opacity: 0.6;
            cursor: not-allowed !important;
            pointer-events: none;
        }
    </style>
    <?php
}

add_action('wp_enqueue_scripts', 'booking_enqueue_scripts');
function booking_enqueue_scripts() {
    wp_enqueue_script('booking-form', get_stylesheet_directory_uri() . '/js/booking-form.js', array('jquery'), '1.2', true);
    wp_localize_script('booking-form', 'bookingAjax', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce' => wp_create_nonce('booking_nonce')
    ));
}
?>

*/
