Support

Home Forums Event Espresso Premium espresso_event_tickets_available() gives me multiple prices instead of one

espresso_event_tickets_available() gives me multiple prices instead of one

Posted: July 18, 2019 at 9:07 am


adasch

July 18, 2019 at 9:07 am

Hi,
I use this code to echo the price for an available ticket
<?php echo espresso_event_tickets_available($post->ID, false, true); ?>

I have ONE event with 4 dates (1 is in the past, 3 are upcomming).

So what I get is three times the price, like
– 123€
– 123€
– 123€

I guess it’s because there are three dates left, but as it is just ONE ticket, I’d like to show the price only once.

Did I misuse espresso_event_tickets_available() for this purpose?

thanks!


Tony

  • Support Staff

July 18, 2019 at 9:19 am

Hi there,

I think so, yes.

Can you link me to the event so I can see your setup?


adasch

July 18, 2019 at 9:51 am

This reply has been marked as private.


adasch

July 18, 2019 at 9:52 am

This reply has been marked as private.


adasch

July 18, 2019 at 9:54 am

This reply has been marked as private.


Josh

  • Support Staff

July 18, 2019 at 2:48 pm

Hi,

If you follow the source of espresso_event_tickets_available() you’ll note that it loops through all the datetimes.

What you could do instead is get the related ticket object for the event and get its price. e.g.

$event = EEH_Event_View::get_event($post->ID);
$html = '';    
$tickets = array();
    if ($event instanceof EE_Event) {
        $tickets = $event->tickets();
    }
    foreach ( $tickets as $ticket ) {
        if ( $ticket instanceof EE_Ticket ) {
            $html .= $ticket->price(); // you could use money_format() or similar here
        }
    }
    echo $html;


adasch

July 19, 2019 at 2:09 am

thank you (again) 🙂

The support post ‘espresso_event_tickets_available() gives me multiple prices instead of one’ 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