Trying to display multiple ticket prices

Home Forums Ticket Products Event Tickets Plus Trying to display multiple ticket prices

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #937507
    liblogger
    Participant

    Hi there,

    We have events with different ticket prices – usually Full price and Subsidised, or Full price and Free – and I’ve been trying to get these prices to display correctly in the event pages.

    Initially, I couldn’t get the snippet here: https://theeventscalendar.com/knowledgebase/filtering-to-show-woocommerce-tickets-prices/ to work at all, but I eventually realised that if I removed the initial check to see if the cost was empty, the filter works for events with full price and subsidised tickets. However, it doesn’t display correctly when one of the tickets is free – in this case, it only displays the full price ticket.

    I want to check that a) changing if ( empty($cost) && class_exists('TribeWooTickets') ) to if ( class_exists('TribeWooTickets') ) isn’t going to do anything catastrophic elsewhere, and b) if there’s a way to display the price range as Free – £N rather than just £N.

    #937713
    Barry
    Member

    Hi!

    Except that you wish to display a price range (rather than a single ticket price) you shouldn’t need the snippet referenced in the KB article you linked to – which I think may be in need of some revision.

    Would something like this work for you instead?

    add_filter( 'tribe_get_cost', 'show_ranged_ticket_costs', 20, 3 );
    
    function show_ranged_ticket_costs( $cost, $event_id, $formatted ) {
    	if ( ! tribe_events_has_tickets( $event_id ) ) return $cost;
    
    	$min = $max = null;
    
    	foreach ( TribeEventsTickets::get_all_event_tickets( $event_id ) as $ticket ) {
    		$min = ( $ticket->price < $min || null === $min ) ? $ticket->price : $min;
    		$max = ( $ticket->price > $max ) ? $ticket->price : $max;
    	}
    
    	if ( null === $min )
    		return $cost;
    
    	$formatted_min = ( '0' === $min ) ? 'Free' : tribe_format_currency( $min );
    
    	if ( $min === $max )
    		return $formatted ? $formatted_min : $min;
    
    	return $formatted
    		? $formatted_min . ' &ndash; ' . tribe_format_currency( $max )
    		: "$min &ndash; $max";
    }

    Remember also that we’re always on the look out for new feature requests!

    If you’d like to propose support for this sort of feature “out of the box” please do feel free to post a request – or add your support to any suitable existing request – over on our UserVoice page 🙂

    I hope that helps.

    #937979
    liblogger
    Participant

    Hi Barry, thanks for the quick response.

    That does seem to work – the only thing is that if we only have free tickets, it doesn’t display anything, but I think that was the default display anyway?

    I’ll look at posting a feature request – seems like an obvious thing to have!

    #938166
    Barry
    Member

    For that last issue I’m going to go ahead and log a bug report in any case, so you don’t need to post a feature request 🙂

    The problem isn’t with the snippet – it is the fact that in the default single-event.php template it treats “0” (free) and “” (no cost) as one and the same – and it only causes the cost to be displayed if the value is something other than those.

    With that in mind, an easy fix could be to override single-event.php and change this line (approx line 34):

    <?php if ( tribe_get_cost() ) : ?>

    To:

    <?php if ( '' !== tribe_get_cost() ) : ?>

    Would that work for you?

    #938420
    liblogger
    Participant

    The missing ‘Free’ isn’t too much of a problem for us at the moment – we have more unpaid events than paid events, so I may just add a line across the site to say that all events are free unless otherwise indicated. The display of the price range – when used – was more pressing!

    I’ll make a note of the possible template edit, though. Thank you 🙂

    #938446
    Barry
    Member

    My pleasure 🙂

    I’ll go ahead and close out this topic in that case but of course if anything else crops up please don’t hesitate to open a new topic and let us know – one of the team will be only too happy to help.

    Thanks again!

    #965765
    Leah
    Member

    Hi there,

    Thanks again for your post. We wanted to get in touch and let you know that although we weren’t able to address this issue in our upcoming 3.10 release, it is still very much a priority. We have a ticket in our system and will be investigating a solution for a future version. Thank you for your patience and support while we work on this!

    Cheers,
    The Events Calendar Team

    #987982
    Leah
    Member

    Hello,

    Thank you again for bringing this issue to our attention. We’re happy to say that we have added a fix for this into our upcoming version 3.11 release. Keep an eye on your Updates page for the new version. If you have any trouble with the update (or are still seeing this problem after you update) please start a new thread and we’d be happy to help out.

    Thank you for your patience while we got this release ready to go!

    Best,
    Leah
    and the rest of The Events Calendar team

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Trying to display multiple ticket prices’ is closed to new replies.