Support

Home Forums Event Espresso Premium Returning a Single Price for an event

Returning a Single Price for an event

Posted: June 19, 2016 at 2:37 am


Andrew Moreton

June 19, 2016 at 2:37 am

Hi

I’m running events that have only one level of pricing and only one venue – so any event can only have one price or venue associated with it.

I’m using EE_Event_List_Query() to pull the details of event dates and timing and would like to add venue and price to this.

Is this possible – if not how might I approach it?

This is the code I’m currently using:

<ul class=”events”>
<?php
$atts = array(
‘title’ => NULL,
‘limit’ => $how_many_upcoming_courses_to_display,
‘css_class’ => NULL,
‘show_expired’ => FALSE,
‘month’ => NULL,
‘category_slug’ => NULL,
‘order_by’ => ‘start_date’,
‘sort’ => ‘ASC’
);
// run the query
global $wp_query;
$wp_query = new EE_Event_List_Query( $atts );
if (have_posts()) : while (have_posts()) : the_post();
?>

<li class=”course_listing group”><?php the_post_thumbnail();?>

<div class=”course_details”>

<?php do_action( ‘AHEE_event_details_after_the_event_title’, $post ); ?>
<?php $datetime = espresso_event_date_obj($post->ID);
$start_day = $datetime->start_date(‘l’);
$start_time = $datetime->start_time(‘g:i a’);
$start_date = $datetime->start_date(‘F j, Y’);
$start_date_without_year = $datetime->start_date(‘F j’);
$end_time = $datetime->end_time(‘g:i a’);
$end_date = $datetime->end_date(‘F j, Y’);?>

<h2>
<?php the_title(); ?> – <span class=”course_date_range”>
<?php if($start_date==$end_date):?>
<?php echo $start_date;?>
<?php else:?>
<?php echo $start_date_without_year;?>
<?php endif;?>
<?php if($start_date!==$end_date):?>
– <?php echo $end_date;?>
<?php endif;?>
</span>

</h2>

” class=”full_details”><?php the_title();?> – full course details…
<?php espresso_event_reg_button();?>
</div>

<?php
endwhile;
else:
?>

  • No Upcoming Events
  • <?php
    endif;
    // now reset the query and postdata
    wp_reset_query();
    wp_reset_postdata();
    ?>

    Thanks!,

    Andrew


    Tony

    • Support Staff

    June 20, 2016 at 6:04 am

    The price is assigned to the tickets and tickets are assigned to the datetime, so as you have the datetime already you can use:

    $tickets = $datetime->tickets();

    $tickets will then be an array of EE_Ticket objects even if you have a single ticket.

    So you want to grab the single ticket from the array:

    $ticket = reset($tickets);

    Then output the price:

    if( $ticket instanceof EE_Ticket ) {
        $ticket_price = $ticket->get_ticket_total_with_taxes();
        echo $ticket_price;
    }

    You may also want to use something like:

    echo EEH_Template::format_currency( $ticket_price );

    I would recommend installing Kint Debugger, you can then wrap each variable within d(); to see what is available within the object.

    The support post ‘Returning a Single Price for an event’ 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