- Issue created by @mylocaltrades
- š¬š§United Kingdom mylocaltrades
Suggested Code Updates for "Allow Guest Seats & Price Per Guest" Feature
File: webform_booking/src/Form/WebformBookingSettingsForm.php
Purpose: Add an option in the admin UI to enable guest seats and set a price per guest.$form['allow_guest_seats'] = [ '#type' => 'checkbox', '#title' => $this->t('Allow guests'), '#description' => $this->t('Enable this to allow users to bring guests.'), '#default_value' => $config->get('allow_guest_seats'), ]; $form['max_guest_seats'] = [ '#type' => 'number', '#title' => $this->t('Maximum Guests per Booking'), '#description' => $this->t('Set the maximum number of guests a user can bring.'), '#default_value' => $config->get('max_guest_seats'), '#min' => 0, '#step' => 1, ]; $form['price_per_guest'] = [ '#type' => 'textfield', '#title' => $this->t('Price per Guest'), '#description' => $this->t('Set a separate price for guests.'), '#default_value' => $config->get('price_per_guest'), '#size' => 10, '#maxlength' => 10, '#states' => [ 'visible' => [ ':input[name="allow_guest_seats"]' => ['checked' => TRUE], ], ], ];
File: webform_booking/src/Plugin/WebformElement/BookingSeats.php
Purpose: Modify the booking seat selection form to include guest selection.if ($config->get('allow_guest_seats')) { $element['guest_seats'] = [ '#type' => 'number', '#title' => $this->t('Number of Guests'), '#description' => $this->t('Select the number of guests (max @max)', ['@max' => $config->get('max_guest_seats')]), '#min' => 0, '#max' => $config->get('max_guest_seats'), '#step' => 1, ]; }
File: webform_booking/src/Service/AvailabilityService.php
Purpose: Modify the availability logic to reduce slot capacity based on both booked seats and guests.$seats_booked = $submission->getElementData('seats'); $guest_seats = $submission->getElementData('guest_seats') ?? 0; $total_seats_used = $seats_booked + $guest_seats; // Ensure availability calculation includes guests. $available_seats = $this->getAvailableSeats($webform_id, $slot_time); if ($total_seats_used > $available_seats) { throw new WebformSubmissionException($this->t('Not enough seats available for this slot.')); }
File: webform_booking/src/Payment/PaymentService.php
Purpose: Ensure guest pricing is added to the total payment.$seats_booked = $submission->getElementData('seats'); $guest_seats = $submission->getElementData('guest_seats') ?? 0; $seat_price = $this->getPricePerSeat($webform_id); $guest_price = $this->getPricePerGuest($webform_id); $total_price = ($seats_booked * $seat_price) + ($guest_seats * $guest_price);
Summary of Changes
- Adds an admin setting to enable/disable guest seats.
- Allows users to select guests while booking.
- Ensures guests reduce availability (no overbooking).
- Supports different pricing for seats vs guests.
- Modifies PayPal/Stripe payment logic to charge guests separately.
Would the module maintainer consider adding this feature?
Iām happy to test this functionality, provide additional code, or even help submit a patch if needed.
Thanks for your time, and let me know what you think.