Allow Guest Seats & Price Per Guest in Webform Booking

Created on 18 February 2025, 3 months ago

Problem/Motivation

Currently, Webform Booking allows users to book seats per slot, with a fixed price per seat. However, in some scenarios, businesses may allow guests (non-paying or at a different price) while still reducing available seats per slot.

For example, a pottery painting studio allows each person to book seats but also bring up to two guests who may or may not be paying. The problem is that:

  • There is no option to add guests alongside the main booking.
  • The total seats available per slot should decrease even if a guest is included.
  • The price per guest might be lower or free, which is not currently configurable.

Steps to reproduce

  1. Go to Webform Booking and configure a booking form.
  2. Notice that there is only an option for selecting paid seats.
  3. There is no way to distinguish between a regular booked seat and a guest seat.
  4. Payments are processed only per booked seat, with no separate guest pricing option.

Proposed resolution

To address this, I propose adding the following new features:

1 - Guest Seats Option

  • Allow users to add up to 2 guest seats per booking.
  • Guest seats should reduce total available seats from the slot without being full bookings.
  • The number of guests should be configurable (e.g., max 2 guests per booking).

2 - Price per Guest Field

  • Add a new admin setting for "Price per Guest" (separate from price per seat).
  • When booking, the total amount should be calculated as: (Seats Ɨ Price per Seat) + (Guests Ɨ Price per Guest)
  • This should be reflected in PayPal payment processing.

3 - Guest Information Fields

Optionally collect guest names or mark them as "non-painters" (for scenarios like pottery studios).
This should be stored in the webform submission data.

UI Changes:

  • Add "Allow Guests" option in Webform Booking Settings.
  • Add a "Price per Guest" field in seat pricing settings.
  • Update seat selection field in the webform to include guest selection.

API Changes:

  • Update how seat availability is stored to account for guests.
  • Modify payment calculations to support different prices for seats vs guests.
  • Ensure PayPal integration supports guest pricing.

Data Model Changes:

  • Add a new field in webform_submission_data to store number of guests per booking.
  • Modify seat availability logic in webform_booking.module.

Remaining tasks

  • Discuss feasibility with the maintainer.
  • Provide example use cases (e.g., pottery painting, escape rooms, workshops).
  • Share any sample code to assist with development.

Additional Information:

I’m happy to help with testing, feedback, or even providing some sample code if this feature is considered useful! Let me know how I can contribute. 😊

✨ Feature request
Status

Active

Version

1.1

Component

Code

Created by

šŸ‡¬šŸ‡§United Kingdom mylocaltrades

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mylocaltrades
  • šŸ‡¬šŸ‡§United Kingdom mylocaltrades
  • šŸ‡¬šŸ‡§United Kingdom 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.

Production build 0.71.5 2024