add_action('wp_loaded', 'handle_amela_reservation_logic'); function handle_amela_reservation_logic() { if (isset($_POST['action']) && $_POST['action'] === 'wpamelia_api') { // Detectamos una reserva de Amelia. $appointment = json_decode(file_get_contents('php://input'), true); if (!$appointment || !isset($appointment['serviceId'])) { return; // No es una reserva válida. } // IDs de canchas $court_2_id = 43; // Fútbol 11 $associated_courts = [16, 36, 39]; // Fútbol 7 $service_id = $appointment['serviceId']; $booking_start = $appointment['bookingStart']; if ($service_id == $court_2_id) { foreach ($associated_courts as $court_id) { if (!is_court_available($court_id, $booking_start)) { throw new Exception("La cancha $court_id ya está ocupada en ese horario."); } } } elseif (in_array($service_id, $associated_courts)) { if (!is_court_available($court_2_id, $booking_start)) { throw new Exception("La cancha 2 (Fútbol 11) ya está ocupada."); } } mark_court_as_booked($service_id, $booking_start); } } // Verificar disponibilidad function is_court_available($court_id, $booking_start) { $url = "https://tu_dominio.com/wp-admin/admin-ajax.php?action=wpamelia_api&call=/api/v1/appointments"; $response = wp_remote_get($url); if (is_wp_error($response)) { throw new Exception("Error al consultar disponibilidad."); } $appointments = json_decode(wp_remote_retrieve_body($response), true); foreach ($appointments as $appointment) { if ($appointment['serviceId'] == $court_id && $appointment['bookingStart'] == $booking_start) { return false; } } return true; } // Marcar la cancha como ocupada function mark_court_as_booked($court_id, $booking_start) { error_log("Cancha $court_id marcada como ocupada desde $booking_start."); }

Uncategorized

Parece que no hemos podido encontrar lo que estás buscando. Quizá pueda ayudarte una búsqueda.

Scroll al inicio