Support

Home Forums Event Espresso Premium Ticket List Filtering

Ticket List Filtering

Posted: August 2, 2023 at 9:24 am

Viewing 10 reply threads


roodude

August 2, 2023 at 9:24 am

Is there a way to filter the tickets shown when using the ticket list shortcode? I’m looking for a simple way to show some tickets on one page, and some on another. All are for the same event and date/time. All I would really need is a filter or shortcode argument that could exclude certain tickets in a given context.


Tony

  • Support Staff

August 2, 2023 at 2:36 pm

There’s a filter run on the tickets displayed on the ticket selector which sound like what you need.

Take a look at FHEE__EventEspresso_modules_ticketSelector_DisplayTicketSelector__getTickets within core, that allows you to filter the tickets using custom functions.

Is that what you need?


roodude

August 2, 2023 at 4:09 pm

I think this is definitely the right track. Forgive me if I’m wrong, but it looks like all of the props of the tickets are protected (if I’m reading this right when var_dumping $tickets). What would be the best way to access the ID of each ticket assigned for the event?

Here’s basically what I am trying to achieve, if that paints a clearer picture.

  1. Check the current page, if the page ID matches, execute the following logic, else return the list of tickets as normal.
  2. Check each ticket’s ID, if the ID matches one of the IDs that I don’t want to show, remove it from the list.

I found the filter you suggested, but I’m having trouble understanding what the safest way is to modify it in this instance because of the amount of data in the $tickets object.


roodude

August 2, 2023 at 4:13 pm

Clarification, when I say ‘modify’ I mean via my own custom function added to functions.php, not modifying the source code itself.


Tony

  • Support Staff

August 3, 2023 at 3:37 am

Forgive me if I’m wrong, but it looks like all of the props of the tickets are protected (if I’m reading this right when var_dumping $tickets).

Yep, a lot of properties (and methods) are, we have getters and setters for most.. which leads onto…

What would be the best way to access the ID of each ticket assigned for the event?

$ticket->ID() will give you the ID.

I’m not a far on var_dump, personally, I use Kint and there’s a plugin for it:

https://wordpress.org/plugins/kint-debugger/

BUT, they haven’t updated it to be PHP 8 compatible, so someone forked it and did just that:

https://github.com/DuckDivers/kint-debugger

Install that as a plugin and using d($ticket);

That will give you a MUCH better output and if you view the methods available on the object you’ll soon find everything you are looking for 🙂

I found the filter you suggested, but I’m having trouble understanding what the safest way is to modify it in this instance because of the amount of data in the $tickets object.

Hmmm so you’ll already have the exact ticket ID’s for each page you want to display these? Where will you have those?

I’m wondering if it’s going to be quicker/more efficient to just repull the tickets using the ID’s or filter the array.


roodude

August 3, 2023 at 10:12 am

Thanks for the tip on Kint, I’m eager to try it. Unfortunately, it’s not working, or I’m doing something wrong. Here’s my code so far, just for testing the output.

add_filter('FHEE__EventEspresso_modules_ticketSelector_DisplayTicketSelector__getTickets', 'ndig_filter_EE_tickets');

function ndig_filter_EE_tickets( $tickets ){
	foreach($tickets as $ticket){
		$count++;
                //Limited to just 2 tickets since output is huge for now
		if($count < 2){
			
			d($ticket); 
		}
	}
	return $tickets;
}

But when I run that (with either version of Kint active), I get the following:
PHP Fatal error: Uncaught Error: Typed property EE_Datetime_Field::$_blog_offset must not be accessed before initialization in [redacted]/wp-content/plugins/kint-php-debugger/src/kint-php/kint/inc/kintParser.class.php:496

Also when I var_dump($ticket->ID) in a foreach loop i get NULL.

To your point at the end of your last response, what I meant was I am going to know the tickets I want excluded ahead of time, so if I can just filter the array, that would work for what I need to do. The only reason I am doing this programmatically is because on one page I want to show tickets 1, 2, and 3, and on another page I’ll want to show tickets 4, 5, and 6, but I still need everything under one event and datetime. So for the first page I was thinking I would just exclude 4, 5, and 6, and vice versa for the second page, but I am open on what the best way to do that actually is.


Tony

  • Support Staff

August 3, 2023 at 11:44 am

But when I run that (with either version of Kint active), I get the following:
PHP Fatal error: Uncaught Error: Typed property EE_Datetime_Field::$_blog_offset must not be accessed before initialization in [redacted]/wp-content/plugins/kint-php-debugger/src/kint-php/kint/inc/kintParser.class.php:496

No, your not doing anything wrong, that’s from a change we made that’s been fixed in the next version, it only comes up when using Kint (or trying to access the property).

The fix is to go to: \event-espresso-core\core\db_models\fields\EE_Datetime_Field.php

Find protected int $_blog_offset

Change it to protected int $_blog_offset = 0;

Now kint should work. I usually don’t advise modifying core, but as that’s a change we’ve already included in our next version of EE it wont matter here.

Also when I var_dump($ticket->ID) in a foreach loop i get NULL.

Its a method so:

var_dump($ticket->ID());

Should output the value.

To your point at the end of your last response…

yeah, use the method you currently are, if it doesn’t work out for what you need we’ll look at switching it out.


roodude

August 3, 2023 at 2:10 pm

Okay, I’ve got most of the logic working now, I’m still struggling with actually filtering out the unwanted ticket. I thought unset would work, but apparently it has no effect.

Here’s my code so far:
https://pastebin.com/CSKc3tHM

All of the test echo statements fire when they should so I know the logic is right, its actually removing the ticket that’s proved challenging so far.


Tony

  • Support Staff

August 4, 2023 at 5:45 am

So unset() destroys the variable you pass to it.

Your passing $ticket which is a local variable to the foreach loop so it’s being unset within that function, not unsetting the array your returning.

So you need to do something like:

foreach($tickets as $key => $ticket){

Your foreach now has the key from each element in the array and each element is passed as $ticket.

Then swap your unset($ticket) for unset($tickets[ $key ]);

Thats removing the elements from the array that your filtering and then returning.


roodude

August 4, 2023 at 1:31 pm

Perfect! This is exactly what I needed. Thank you for your help. In case anyone else runs into a similar issue, here’s what I ended up doing.

https://pastebin.com/VArEgtsC

If I could ask a followup question, is there any documentation of the methods/filters available for stuff like this? I’m pretty good at following along or modifying examples, but a lot of this is way over my head.


Tony

  • Support Staff

August 7, 2023 at 5:48 am

So, I’d love to say yes, but, we have literally thousands of hooks within EE.

Filter hooks are all prefixed with FHEE__

Action hooks are all prefixed AHEE__

Searching the codebase will return roughly 3000 hooks, not including the dynamic versions where a hook name is generated on the fly as steps progress or the WP core hooks that also apply, so there are a LOT of hooks to document.

Adding documentation for all of those is going to take a long time and unfortunately for the number of users it would actually benefit we can’t put it as a high priority as much as we would love to.

Developers (who the hooks are intended for) will know how to search/use them or will at least find the hook and post up requesting additional details if they can’t figure something out specific to our code base, I/we will help with those if we but also can’t write out custom functions for people without purchasing a support token (we simply don’t have the capacity to take on custom snippets).

In short, as much as we’d love to walk through the documentation for all of Event Espresso we have to prioritise where we spend the time doing so. Documentation/examples for customizations is not something we support, although we do add the details we can when possible 🙂

Viewing 10 reply threads

The support post ‘Ticket List Filtering’ 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