Display ticket price
WordPress Event Management, Calendars & Registration › Forums › General Question › Display ticket price
This topic contains 11 replies, has 3 voices, and was last updated by Stephen Harris 10 years, 1 month ago.
-
AuthorPosts
-
February 6, 2014 at 11:31 am #9398
Hello there,
I am doing a simple event list and I am looking for the right function to get the ticket price – but I can’t find it. I’m sure I need eo_get_ticket in some way. I must be missing something somewhere, because I’m sure it’s actually very simple.
Thanks a million.Charlotte Kitto
February 6, 2014 at 12:39 pm #9402Hi Charlotte,
There are two functions you can use to retrieve an event’s tickets:
eo_get_event_tickets()
: http://codex.wp-event-organiser.com/function-eo_get_event_tickets.htmleo_get_event_tickets_on_sale()
: http://codex.wp-event-organiser.com/function-eo_get_event_tickets_on_sale.html
(The latter is identical to first, except it removes any tickets that aren’t ‘on sale’ if you’ve assigned an on sale period for that ticket). If you’re selling ‘by date’ then you’ll probably want to pass the occurrence ID as the second argument too. Otherwise ignore it.
These functions return an array of arrays (tickets). This outer array is indexed by the ticket ID so you may want to use
array_shift()
if you need the first ticket:$tickets = eo_get_event_tickets( $event_id, $occurrence_id ); $ticket = array_shift( $tickets ); $raw_price = $ticket['price']; $formatted_price = eo_format_price( $raw_price, true ); //Format price with currency
As illustrated above you can use
eo_format_price()
to ensure the price is well formatted and includes the currency symbol (http://codex.wp-event-organiser.com/function-eo_format_price.html).Stephen Harris
February 6, 2014 at 1:07 pm #9403Thanks, Stephen, thank you for giving me that information. You are really good at looking after everyone!
I thought I could just stick eo_format_price() in with the eo_get_the_start() code etc to begin with, but that didn’t work.
This is the code that I have at the moment – I am now at least getting a value for the one that I have put a price against. But I am getting a value of “1” instead of the 150 which is the ticket price.http://pastebin.com/eaXmwGYh This is my code.
Charlotte Kitto
February 6, 2014 at 1:13 pm #9404You’re welcome 🙂
Regarding the codebin you posted, you need to set the value of
$event_id
and$occurrence_id
. The following should work:<?php $events = eo_get_events(array( 'numberposts'=>5, 'event_start_after'=>'today', 'event-category'=>'cork', )); if( $events ){ global $post; foreach( $events as $post ){ setup_postdata($post); $tickets = eo_get_event_tickets( $post->ID, $post->occurrence_id ); $ticket = array_shift( $tickets ); $raw_price = $ticket['price']; $formatted_price = eo_format_price( $raw_price, true ); //Format price with currency ?> <a href="<?php the_permalink(); ?>"><div class="event-wrap"> <div class="event-title"> <h5><?php the_title(); ?></h5> </div> <div class="event-date"> <span class="day"><?php echo eo_get_the_start('j'); ?></span><br/> <span class="month"> <?php echo eo_get_the_start('M'); ?> </span> </div> <div class="event-detail"><?php echo $formatted_price; ?> </div> <div class="event-detail"><?php the_field( "duration" ); ?></div> <div class="event-detail">BOOK NOW</div> </div></a> <?php } wp_reset_postdata(); }else{ echo 'No Upcoming Events'; }?>
-
This reply was modified 11 years, 1 month ago by
Stephen Harris.
Stephen Harris
February 6, 2014 at 1:31 pm #9406No, it still pulls the price as 1 instead of 150 – the page I am working on is : http://marydaly.ie/training-schedule/
Any other suggestions?C
Charlotte Kitto
February 6, 2014 at 1:34 pm #9407Could you try
var_dump()
-ing$post->ID
,$post->occurrence_id
and$ticket
to make sure they are all as expected? You may want tovar_dump($tickets)
as well to help find where in the chain things are going wrong.Stephen Harris
February 6, 2014 at 1:47 pm #9408Okay I did that and the $tickets looks empty. if you see the site link you can see the results. I am working live but hidden away.
Charlotte Kitto
February 6, 2014 at 1:54 pm #9409echo eo_format_price($raw_price, ‘price’, true );
changing $ticket to $raw_price worked
I hope that doing it that way won’t make it messy in the future in some way.
Thanks for helping me.
C
Charlotte Kitto
February 6, 2014 at 2:00 pm #9412Ah, oops, my mistake :). I’ve corrected the code now.
Stephen Harris
February 3, 2015 at 7:57 pm #14920Hello Stephen,
My events have only one ticket type per event. I use that same code to display the price in “event-meta-event-single.php”, but i works sometimes, and sometimes not (displaying “free” instead of the ticket’s price) :
<?php $tickets = eo_get_event_tickets( $post->ID, $post->occurrence_id ); $ticket = array_shift( $tickets ); $raw_price = $ticket['price']; $formatted_price = eo_format_price( $raw_price, true ); //Format price with currency if( $raw_price > 0 ){ echo $formatted_price; }else{ echo 'Free'; } ?>
Nicolas Massart
February 4, 2015 at 3:02 pm #14934I found a solution removing the argument “$post->occurrence_id” :
<?php $tickets = eo_get_event_tickets( $post->ID ); $ticket = array_shift( $tickets ); $raw_price = $ticket['price']; $formatted_price = eo_format_price( $raw_price, true ); //Format price with currency if( $raw_price > 0 ){ echo $formatted_price; }else{ echo 'Free'; } ?>
Nicolas Massart
February 4, 2015 at 3:14 pm #14935Hi Nicolas,
The
$post->occurrence_id
should only be passed if you are selling tickets by date,Stephen Harris
-
AuthorPosts