Support

Home Forums Event Espresso Premium Display availability of various ticket types in Grid View Template

Display availability of various ticket types in Grid View Template

Posted: March 9, 2021 at 2:31 pm

Viewing 8 reply threads


Peter

March 9, 2021 at 2:31 pm

We have two kinds of tickets – one for logged in users and another for general visitors.

We use the Grid View Template on our home page. It can show the total number of available spaces by calling “DTT_reg_limit”.

However, we only want to show the number of tickets available for general visitors on the Grid View Template, This way, casual users can see the number of places actually available to them and not the total number of tickets available – which includes tickets only visible to logged-in users.

The information we need is available for each ticket type from the “wp_esp_ticket” table via the TKT_qty and TKT_sold fields. Any suggestions on how I might be able to return that data so we can show the number of tickets remaining for each ticket type and only display the relevant number?


Tony

  • Support Staff

March 10, 2021 at 3:12 am

Hi Peter,

May I ask, are you using our model system?

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

If not, I recommend taking a look over those docs first as the models make grabbing this data easier, for example, you mentioned DTT_reg_limit so how are you calling that?

Directly from the DB? Or using something like $datetime->reg_limit();?

The data you need on the ticket can be shown using $ticket->remaining();

Which shows the number of remaining spaces on the ticket assuming $ticket is an instance of EE_Ticket.

You mentioned you have kinds of tickets, so is that always just two tickets within the event? One with a capability set and the other without?


Peter

March 10, 2021 at 3:40 am

Hi Tony,
Yes we always have just two ticket types – one with capability set and one without.

We are modifying the EE Grid View Template which currently calls DTT_reg_limit which appears to link to $datetime->reg_limit();.

I have not looked at your model system, but it looks interesting. Do you have any sample code for correctly instantiates $ticket using EE_Ticket?

Thanks for taking the time to reply.
Peter


Peter

March 10, 2021 at 3:41 am

Hi Tony,
Yes we always have just two ticket types – one with capability set and one without.

We are modifying the EE Grid View Template which currently calls DTT_reg_limit which appears to link to $datetime->reg_limit();.

I have not looked at your model system, but it looks interesting. Do you have any sample code for correctly instantiating $ticket using EE_Ticket?

Thanks for taking the time to reply.
Peter


Tony

  • Support Staff

March 10, 2021 at 4:12 am

Can you post the code for you grid template to a Gist or Pastebin so I can see what you have so far?

For what you are trying to do, use the EE_Datetime object that you have (presumably within something like $datetime) and you can pull related tickets from that.

For example:

$tickets = $datetime->tickets();

Which will return an array of EE_Ticket objects related to that DateTime. Note we have some default where conditions used within the models which can sometimes trip you up when expecting certain objects to be returned. It should affect what you are doing here but worth noting, see HERE.

tickets() can also be passed query params (See Model Query Params), which means you can also specifically pull the ticket without a capability set when not logged in and then specifically pull the ticket with a capability set when logged in. For your current use case, looping over them to check for a capability and then using the correct one isn’t going to cause problems if that’s what you want to do, but the point is there’s a huge amount of flexibility within the model system to get pretty much whatever you want from it.

My recommendation is to use something like Kint Debugger, wrap whatever you are trying to work from in d(); and take a look at the output. It shows all properties and (more importantly for the models) all methods available. Then work from there to use the models in more depth, they make working with EE’s data (and related data like above) much easier once you’ve gotten used to them.


Peter

March 10, 2021 at 11:14 pm

Hi Tony,
Thanks so much for your detailed response. I am in uncharted territory with this, but your notes have given me some clues about where to start. I’ll work through it and when I have something sensible to report, I’ll get back to you.


Tony

  • Support Staff

March 11, 2021 at 3:25 am

As mentioned, theres a couple of ways to go about this but to give an example for one of them, take a look at this:

// Set up where conditions to pull tickets with nothing set in the ticket capability by default.
$where = array(
	'Extra_Meta.EXM_key' => 'ee_ticket_cap_required',
	'Extra_Meta.EXM_value' => array('IS NULL')
);

// If the user is logged in, then we want ticket with a value for ee_ticket_cap_required.
if( is_user_logged_in() ) {
	$where['Extra_Meta.EXM_value'] = array('IS NOT NULL');
}
// Pull the tickets from the datetime, only need 1 ticket? Set limit to 1.
$tickets = $datetime->tickets(array($where, 'limit' => 1));
// The models return arrays of object, so use reset() to pull the first object from the array.
$ticket = reset($tickets);

// Check if $ticket is indeed an EE_Ticket object before trying to use it as one.
if($ticket instanceof EE_Ticket) {
    // Do something with the EE_Ticket object here.
    echo $ticket->remaining();
}

That pulls the tickets (actually just one but could easily be changed) related to the datetime in question. It will pull a ‘public’ ticket by default (a ticket that does not have a capability set on it) but if the user is logged in, pulls a ‘member’ ticket (a ticket with a capability set on it).

Side note, we don’t provide support for customizations but the above should help give you an idea of how to use the models to get what you need 🙂


Peter

March 11, 2021 at 4:37 pm

This reply has been marked as private.


Tony

  • Support Staff

March 15, 2021 at 4:25 am

You’re most welcome.

Viewing 8 reply threads

The support post ‘Display availability of various ticket types in Grid View Template’ 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