Display ticket price

This topic contains 11 replies, has 3 voices, and was last updated by  Stephen Harris 10 years, 1 month ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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
    #9402

    Hi Charlotte,

    There are two functions you can use to retrieve an event’s tickets:

    (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
    #9403

    Thanks, 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
    #9404

    You’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
    #9406

    No, 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
    #9407

    Could you try var_dump()-ing $post->ID, $post->occurrence_id and $ticket to make sure they are all as expected? You may want to var_dump($tickets) as well to help find where in the chain things are going wrong.

    Stephen Harris
    #9408

    Okay 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
    #9409

    echo 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
    #9412

    Ah, oops, my mistake :). I’ve corrected the code now.

    Stephen Harris
    #14920

    Hello 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
    #14934

    I 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
    #14935

    Hi Nicolas,

    The $post->occurrence_id should only be passed if you are selling tickets by date,

    Stephen Harris
Viewing 12 posts - 1 through 12 (of 12 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.