Home › Forums › Ticket Products › Event Tickets Plus › Calling custom functions within a tribe loop
- This topic has 5 replies, 2 voices, and was last updated 8 years, 11 months ago by
David Hager.
-
AuthorPosts
-
April 5, 2017 at 7:58 am #1265020
David Hager
ParticipantHi there,
Last week you helped greatly with creating a function to show the remaining amount of tickets of a specific type of ticket and showing when a event would be full. These functions were the result of this exercise:
<?php //Getting information if tickets are left function tribe_events_single_ticket_soldout( $event = null ) { if ( null === ( $event = tribe_tickets_parent_post( $event ) ) ) { return false; } $some_have_soldout = false; foreach ( Tribe__Tickets__Tickets::get_all_event_tickets( $event->ID ) as $ticket ) { if ( ! $some_have_soldout && 0 == $ticket->stock() ) { $some_have_soldout = true; } } return $some_have_soldout; } //Get ticketamount function tribe_events_single_ticket_surgeon_quant( $event = null ) { if ( null === ( $event = tribe_tickets_parent_post( $event ) ) ) { return false; } foreach ( Tribe__Tickets__Tickets::get_all_event_tickets( $event->ID ) as $ticket ) { $alloyTicketName = $ticket -> name; $alloyTicketStock = $ticket -> stock; if (strpos($alloyTicketName, 'surgeon') !== false) { return $alloyTicketStock; } elseif (strpos($alloyTicketName, 'Surgeon') !== false) { return $alloyTicketStock; } elseif (strpos($alloyTicketName, 'SURGEON') !== false) { return $alloyTicketStock; } } } //Each time a event is written, this function writes the correct message if (function_exists('tribe_events_single_ticket_surgeon_quant') && function_exists('tribe_events_single_ticket_soldout')) { $alloyEventSurgeonTicketsLeft = tribe_events_single_ticket_surgeon_quant(); $alloyEventFullCheck = tribe_events_single_ticket_soldout(); if ($alloyEventSurgeonTicketsLeft > 0) { echo '<span class="alloy-event-spots-open">'. $alloyEventSurgeonTicketsLeft .' spots available!</span>'; } elseif ($alloyEventFullCheck >= 1) { echo '<span class="alloy-event-information-full">Event Full!</span>'; } }Everything seemed to work fine, but I found out now that the last if statement doesn’t seem to be working from within the standard Tribe loops. I think this might be because the first two functions are defined and called from the functions.php file?
I need to use the tribe loop because of the chronological order of upcoming events and filtering past events. Something I can’t seem to be able to figure out how to implement within the normal WordPress loop.
To make it a little more clear, here are my two questions:
1. How to I make these functions work within the tribe loops, so the fields can be shown in the overview?
2. What type of query should I use to show upcoming events in chronological order in a standard WordPress loop?Thanks already!
Kind regards,
David HagerApril 10, 2017 at 8:55 am #1267675Barry
MemberHi David,
I do need to note first of all that we can only offer very limited support for custom dev tasks like this one. That said, I’d be happy to explore this a little more and perhaps bounce some ideas around 🙂
but I found out now that the last if statement doesn’t seem to be working from within the standard Tribe loops
Can you describe what’s going wrong? Is it not behaving as expected or are you receiving an error of some kind?
April 11, 2017 at 3:12 am #1268142David Hager
ParticipantThank you for willing to have a look!
Just for your information. The purpose of the function is to show a span on the event-archive page to show how many specific tickets are remaining or if this specific ticket is sold out.
From within the normal WP loop, the function is called and works, so the span is shown. When I use the same function within the tribe events loop, nothing seems to happen. It seems the tribe loop doesn’t see the function or its variables.
April 11, 2017 at 5:21 pm #1268600Barry
MemberHi David,
If I add both functions to the theme’s functions.php file and add the remaining code within an override of the list/loop.php template (right after list/single.php is included) it appears to function as expected.
I added tickets to two different events (both ticket names included the text ‘Surgeon’). One had 123 units of stock remaining, the other I set to have no stock remaining. It seemed like the code behaved as expected for both events, with 123 spots available! appearing for one and Event Full! for the other.
Perhaps you’ve positioned the code in a different template, or the test conditions I used deviate from what you have locally in some way … but it appears the code is doing its job correctly.
Given that, I’m not sure how much further we can assist with this one (especially, as before, this is very much custom dev territory).
May 3, 2017 at 9:36 am #1278091Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Calling custom functions within a tribe loop’ is closed to new replies.
