Skip to content

Instantly share code, notes, and snippets.

@chrisegg
Last active January 29, 2026 22:46
Show Gist options
  • Select an option

  • Save chrisegg/527e5a7ef0fa542ddcd589e76efc4403 to your computer and use it in GitHub Desktop.

Select an option

Save chrisegg/527e5a7ef0fa542ddcd589e76efc4403 to your computer and use it in GitHub Desktop.
Replaces a registration form with a waitlist form when a custom attendee limit is reached. Counts attendees using a List field and displays seats remaining.
<?php
/**
* Plugin Name: Event Registration Limiter for Gravity Forms
* Description: Dynamically switches between a registration form and a waitlist form
* based on the actual number of attendees registered.
* Author: Chris Eggleston – Gravity Ranger
* Tutorial URL: https://gravityranger.com/automatically-switch-from-a-registration-form-to-a-waitlist-in-gravity-forms/
*
* WHERE TO PUT THIS CODE:
* --------------------------------------------------
* Choose ONE of the following:
*
* OPTION A: Create a small custom plugin
* - Create a file called event-registration-limiter.php
* - Place it in /wp-content/plugins/
* - Paste this entire snippet into the file
* - Activate the plugin in WordPress
*
* OPTION B: Use a code snippet plugin
* - Add this code using WPCode, Code Snippets, etc.
* - Ensure the snippet runs on the front end
*
* OPTION C: functions.php
* - Paste into your active theme’s functions.php file
* - Code will be lost if the theme is changed
*
* --------------------------------------------------
*
* HOW TO USE:
* 1. Create a registration form in Gravity Forms.
* 2. Add a LIST field where EACH ROW represents ONE attendee
* (ex: First Name | Last Name | Email).
* 3. Create a separate waitlist form.
* 4. Place the shortcode on a page and pass the correct IDs.
*
* Example shortcode:
* [event_form_display registration_form_id="1" waitlist_form_id="2" list_field_id="6" max_attendees="100"]
*/
add_shortcode('event_form_display', function($atts) {
/**
* STEP 1: Define shortcode attributes
*
* These allow the snippet to be reused for different events
* without modifying the code.
*/
$atts = shortcode_atts([
'registration_form_id' => 1, // Main event registration form ID
'waitlist_form_id' => 2, // Waitlist form ID
'list_field_id' => 6, // List field ID (each row = 1 attendee)
'max_attendees' => 100 // Event capacity
], $atts);
// Cast values to integers for safety
$registration_form_id = (int) $atts['registration_form_id'];
$waitlist_form_id = (int) $atts['waitlist_form_id'];
$list_field_id = (int) $atts['list_field_id'];
$max_attendees = (int) $atts['max_attendees'];
/**
* STEP 2: Retrieve all active entries for the registration form
*/
$search_criteria = array('status' => 'active');
$entries = GFAPI::get_entries($registration_form_id, $search_criteria);
/**
* STEP 3: Count total attendees
*
* Each row in the List field represents ONE attendee.
* We loop through all entries and sum the row counts.
*/
$total_attendees = 0;
foreach ($entries as $entry) {
$list_value = rgar($entry, $list_field_id);
if (!empty($list_value)) {
$list = maybe_unserialize($list_value);
if (is_array($list)) {
$total_attendees += count($list);
}
}
}
/**
* STEP 4: Calculate remaining seats
*/
$seats_remaining = $max_attendees - $total_attendees;
/**
* STEP 5: Display the correct form
*
* - If the event is full, show the waitlist form
* - Otherwise, show the registration form with seats remaining
*/
if ($seats_remaining <= 0) {
$output = '<div class="gf-event-message">';
$output .= '⚠️ Registration is full. You can join the waitlist below:';
$output .= '</div>';
$output .= do_shortcode(
'[gravityform id="' . $waitlist_form_id . '" title="false" description="false" ajax="true"]'
);
} else {
$output = '<div class="gf-event-message">';
$output .= '🎟️ <strong>' . $seats_remaining . '</strong> seat';
$output .= ($seats_remaining > 1 ? 's' : '') . ' remaining. Register below:';
$output .= '</div>';
$output .= do_shortcode(
'[gravityform id="' . $registration_form_id . '" title="false" description="false" ajax="true"]'
);
}
return $output;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment