Make Reservation
<?php
if (!isset($_GET['course_id'])) {
echo "<p>Invalid course.</p>";
return;
}
$course_id = intval($_GET['course_id']);
$product = wc_get_product($course_id);
if (!$product) {
echo "<p>Course not found.</p>";
return;
}
$slots = get_field('course_slots', $course_id);
if (!$slots) {
echo "<p>No slots available.</p>";
return;
}
?>
<h2><?php echo esc_html($product->get_name()); ?></h2>
<?php
// Messages
if (isset($_GET['reservation_error'])) {
echo '<div class="error" style="color:red;margin-bottom:15px;">'
. esc_html($_GET['reservation_error']) .
'</div>';
}
if (isset($_GET['reservation']) && $_GET['reservation'] === 'success') {
echo '<div class="success" style="color:green;margin-bottom:15px;">'
. 'Reservation successful!'
. '</div>';
}
?>
<form method="post" style="max-width:600px;">
<?php wp_nonce_field('nds_reservation_action', 'nds_nonce'); ?>
<input type="hidden" name="course_id" value="<?php echo esc_attr($course_id); ?>">
<input type="hidden" name="nds_reservation_submit" value="1">
<!-- Honeypot (hidden from humans) -->
<div style="display:none;">
<label>Leave this field empty</label>
<input type="text" name="nds_hp_field" value="">
</div>
<p>
<label>First Name</label>
<input type="text" name="first_name" required>
</p>
<p>
<label>Last Name</label>
<input type="text" name="last_name" required>
</p>
<p>
<label>Phone</label>
<input type="text" name="phone" required>
</p>
<p>
<label>Email Address</label>
<input type="email" name="customer_email" required>
</p>
<p>
<label>Select Slot</label>
<select name="selected_slot" required>
<option value="">Choose a slot</option>
<?php foreach ($slots as $index => $slot):
$total = (int) $slot['total_seats'];
$booked = (int) $slot['booked_seats'];
$available = $total - $booked;
if ($available <= 0) continue;
$start = DateTime::createFromFormat('d/m/Y', $slot['start_date']);
$end = DateTime::createFromFormat('d/m/Y', $slot['end_date']);
$label = $start->format('d M') .
' - ' .
$end->format('d M') .
" ({$available} seats left)";
?>
<option value="<?php echo esc_attr($index); ?>">
<?php echo esc_html($label); ?>
</option>
<?php endforeach; ?>
</select>
</p>
<p>
<button type="submit">Make Reservation</button>
</p>
</form>
Invalid course.

