Support

Home Forums Event Espresso Premium EE4 – Returning ticket prices in a template

EE4 – Returning ticket prices in a template

Posted: October 19, 2016 at 7:57 am

Viewing 6 reply threads


Andrew Moreton

October 19, 2016 at 7:57 am

Hi,

I’m running EE4 and using EE_Event_List_Query as the basis for a query which returns upcoming events along with their start and end dates etc – What I’d like to do is to bring the ticket price along with this.

My events only have one ticket price, so I’m not worried about multiple prices coming along for the ride..

Any ideas? Thanks!

Andrew


Josh

  • Support Staff

October 19, 2016 at 11:54 am

Hi Andrew,

One idea is you can adapt some of the code from step 11 of this tutorial:

https://gist.github.com/lorenzocaum/ef6afefd07c9c5f6f681


Andrew Moreton

October 20, 2016 at 6:36 am

Good idea!

Here’s what I’ve used just in case it helps anyone else -it works fine if your event only has one ticket price…

<?php
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
$ticket = reset( $tickets );
$ticket_price = $ticket->pretty_price();
echo $ticket_price;
?>

thanks Josh,

Andrew


Andrew Moreton

October 22, 2016 at 1:53 am

Actually I was being a bit premature there – it turns out that it works well as long as 8 events are returned, but after that something breaks and NO more of the page is processed, including include get_footer() and other includes..
I’m not sure if there’s anything obvious in the snippet I posted last time that might be doing this – As I say, it works fine up until 8 events, then breaks.. If I remove the code block, everything (footer etc) gets included, if I add it, it works, until 9 items, at which point, it breaks…
Unlikely I know, but do you perhaps have any idea what I might be doing wrong,

thanks,

Andrew


Tony

  • Support Staff

October 24, 2016 at 4:41 am

Hi Andrew,

The above doesn’t point to anything that would cause this.

Have you enabled WP_DEBUG to see if any error is shown when 9 events are shown?

Anything different with the 9th event or does it matter which order they are shown with the above snippet?


Andrew Moreton

October 24, 2016 at 7:17 am

Thanks Tony – you put me on to the right track – it turned out to be a weird bug (or maybe feature!) – The error came when an event’s tickets Sell Until Date had passed…


Tony

  • Support Staff

October 24, 2016 at 8:55 am

Yeah, I see.

You’ll want to check you have an EE_Ticket object before attempting to use the object. For example:

if ( $ticket instanceof EE_Ticket ) { //Do something within $ticket }

espresso_event_tickets_available() only returns available tickets, so if there are none $ticket will == NULL

If you try to run a method on NULL it will thrown an error.

Anyway, I’m glad you found the problem 🙂

Viewing 6 reply threads

The support post ‘EE4 – Returning ticket prices in a 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