Support

Home Forums Event Espresso Premium PHP code to find out if event is sold out

PHP code to find out if event is sold out

Posted: March 24, 2022 at 3:00 pm

Viewing 2 reply threads


TTBC

March 24, 2022 at 3:00 pm

Hi

I have built a custom registration form for VIPS so that they can bypass the required login to book tickets.

What I am wanting to do is the best way to check if the event/ticket has reached the set capacity. The purpose of this is to not render the registration form and show the SOLD out messaging.

I have the event ID and the Ticket ID available on the page.


TTBC

March 24, 2022 at 3:02 pm

Also, this is built into a custom WordPress plugin. It uses a unique 16 varchar GUID as the URL to the page to make it a little harder to find for the general public


Tony

  • Support Staff

March 25, 2022 at 7:40 am

Hi there,

What I am wanting to do is the best way to check if the event/ticket has reached the set capacity.

It really depends on which one of those you want as to which is the best way.

Within a single event, individual datetimes and tickets can be sold out, or the whole event can be sold out, you can check for each individually but for yours use case is sounds like the event as whole will work?

The ‘easiest’ method to check if the event is sold out is using the is_sold_out() method on the EE event class.

If you have an EE_Event object within $event you can do $event->is_sold_out() check for a relatively inexpensive check (its basically just checking the event status to see if its sold out).

Or if you want to check the actual count each time you can pass true to the method to perform a full check against the datetimes/tickets, so $event->is_sold_out(true) (note that this means EE will query every ticket/datetime on the event and compare the values, usually not noticeable unless you have a lot them but worth a not)

If you don’t have the EE_Event class checkout how to use our models:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

It makes working with EE data much easier.

Viewing 2 reply threads

The support post ‘PHP code to find out if event is sold out’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso