By default, users can RSVP to events as many times as they’d like. If you’d prefer to limit users to a single RSVP per person, you can make that happen with some customizations. You can add a snippet to limit the RSVP functionality and then create a template override to customize the appearance of the form once a user has already RSVP’ed.
We’ll walk you through the steps here.
Prerequisites
For this to work, you need to require users to log in before they RSVP. You can find the respective setting under Tickets > Settings > General tab.
The snippet
The first thing you’ll want to do is add the following snippet to your functions.php file:
add_filter( 'tribe_tickets_get_ticket_max_purchase', function( $stock ) {
if ( $stock < 1 ) {
return $stock;
}
return 1;
} );
This will limit the RSVP so that users can only submit a single RSVP at once.
Template override
The next step in the process is to create a template override. If you’re not familiar with template overrides, check out this Knowledgebase article.
Create a file at:
[your-theme]/tribe/tickets/v2/rsvp/actions/rsvp.php
Add the following to that template to include a custom message if a user tries to purchase multiple RSVPs:
<?php
/**
* Block: RSVP
* Actions - RSVP
*
* This is a template override for the following file:
* event-tickets/src/views/v2/rsvp/actions/rsvp.php
*
* Place this template in your own theme by creating a file at:
* [your-theme]/tribe/tickets/v2/rsvp/actions/rsvp.php
*
* See more documentation about our Blocks Editor templating system.
*
* @link https://evnt.is/1amp Help article for RSVP & Ticket template files.
*
* @var Tribe__Tickets__Ticket_Object $rsvp The rsvp ticket object.
*
* @since 4.12.3
* @version 4.12.3
*/
$user = wp_get_current_user();
$event_id = get_the_ID();
/** @var Tribe__Tickets__Tickets_View $tickets_view */
$tickets_view = Tribe__Tickets__Tickets_View::instance();
?>
<div class="tribe-tickets__rsvp-actions-rsvp">
<span class="tribe-common-h2 tribe-common-h6--min-medium">
<?php esc_html_e( 'RSVP Here', 'event-tickets' ); ?>
</span>
<?php if ( ! $tickets_view->has_rsvp_attendees( $event_id, $user->ID ) ) : ?>
<?php $this->template( 'v2/rsvp/actions/rsvp/going', [ 'rsvp' => $rsvp ] ); ?>
<?php $this->template( 'v2/rsvp/actions/rsvp/not-going', [ 'rsvp' => $rsvp ] ); ?>
<?php else : ?>
<p>Sorry - only one per customer!</p>
<?php endif; ?>
</div>
The result
After setting this up, a user who has already RSVP’d to an event should see something like this:
Disable “Going” button
If instead, you’d prefer to disable the “Going” button entirely, you can use the following snippet instead:
<?php
/**
* Block: RSVP
* Actions - RSVP - Going
*
* Override this template in your own theme by creating a file at:
* [your-theme]/tribe/tickets/v2/rsvp/actions/rsvp/going.php
*
* See more documentation about our Blocks Editor templating system.
*
* @link https://evnt.is/1amp Help article for RSVP & Ticket template files.
*
* @var bool $must_login Whether the user has to login to RSVP or not.
* @var Tribe__Tickets__Ticket_Object $rsvp The rsvp ticket object.
*
* @since 4.12.3
* @version 4.12.3
*/
$user = get_current_user_id();
$tickets_view = \Tribe__Tickets__Tickets_View::instance();
$rsvp_count = 0 < $tickets_view->count_rsvp_attendees( get_the_ID(), $user );
$disabled = $must_login || $rsvp_count;
?>
<div class="tribe-tickets__rsvp-actions-rsvp-going">
<button
class="tribe-common-c-btn tribe-tickets__rsvp-actions-button-going tribe-common-b1 tribe-common-b2--min-medium"
type="submit"
<?php tribe_disabled( $disabled ); ?>
>
<?php echo esc_html_x( 'Going', 'Label for the RSVP going button', 'event-tickets' ); ?>
</button>
</div>