Home › Forums › Ticket Products › Event Tickets Plus › Output the original number of tickets in the frontend event list
- This topic has 7 replies, 2 voices, and was last updated 6 years ago by salilou.
-
AuthorPosts
-
April 6, 2018 at 4:42 am #1498426salilouParticipant
Hi,
I use the Ticket Plus plugin and would like to output the original number of tickets in the frontend event list.
Something like “5 of 10 tickets available”.
At the moment there is only “5 tickets available”.
This should of course calculate all ticket types.
Is that possible by using a hook or filter?
Thank you!April 9, 2018 at 10:12 am #1500702AndrasKeymasterHi Salilou,
Thanks for reaching out!
Let me try to help you out with this question. Though we are limited supporting customizations as stated in our support policy, I can try to give you some pointers here.
For what you want to achieve probably a template override (or more if you want this on several views, like month view and single event view as well) would be best. You can find a guide on template overrides in our Themer’s Guide – https://theeventscalendar.com/knowledgebase/themers-guide/
And here are three functions from our documentation which will help you show the number of tickets:
- https://theeventscalendar.com/function/tribe_events_has_unlimited_stock_tickets/
- https://theeventscalendar.com/function/tribe_events_count_available_tickets/
- https://theeventscalendar.com/function/tribe_events_has_tickets/
Hope this help you get started. Let me know if you need further guidance.
Cheers,
AndrasApril 15, 2018 at 11:58 am #1507712salilouParticipantThank you, Andras!
But is there a function to get the total amount of tickets?
I do not mean the still available, but the original total number.
Greetings,
HannesApril 16, 2018 at 3:17 am #1507938AndrasKeymasterHi Hannes,
I believe you are looking for this functions then:
Does this do the trick?
Andras
April 16, 2018 at 11:22 am #1508401salilouParticipantThank you Andras, that’s it!
Now I have to hook in the function tribe_tickets_buy_button in the file
event-tickets/src/template-tags/tickets.php, line 178
Do I have to copy the whole file to my child theme (what I would like to avoid)
or can I use a hook?
My aim is to change the text before the button from
“%s tickets left”
to
“%s of %s tickets left”
Thank you!April 17, 2018 at 2:54 am #1508887AndrasKeymasterYou should be able to hook into this filter:
apply_filters( 'tribe_tickets_buy_button', $html, $parts, $types, $event_id );
(Line 275 in the same file.)
It will probably be the ‘$html’ variable that you’ll need to change.
Does this help?
Andras
April 21, 2018 at 3:23 pm #1513028salilouParticipantThank you. I have built a code snippet.
For anyone who also wants to output the total ticket capacity./* add original total ticket capacity */
add_filter('tribe_tickets_buy_button', 'salilou_tribe_tickets_buy_button');
function salilou_tribe_tickets_buy_button($html) {
$my_ticket_capacity = tribe_tickets_get_capacity( $event_id );
$html['stock'] = str_replace('', ' of ' . $my_ticket_capacity . '', $html['stock']);
return $html;
}April 23, 2018 at 2:47 am #1513500AndrasKeymasterHi Hannes,
This is awesome, thanks for sharing that!
Since this is marked resolved I am going to close this ticket, but if you need anything else related to this topic or another please create a new ticket and we’ll be happy to help.
Cheers,
AndrasPS: We’d be grateful if you would give us feedback on your satisfaction with support. Just click on one of the classy looking emojis below. 🙂 If you can spare a few words, that’s even better. Thanks!
PS2: If you like our plugins, and you didn’t yet do so 🙂 we would also be happy to receive a review in the wordpress.org repository. Much appreciated!
https://wordpress.org/support/view/plugin-reviews/the-events-calendar/
https://wordpress.org/support/view/plugin-reviews/event-tickets/ -
AuthorPosts
- The topic ‘Output the original number of tickets in the frontend event list’ is closed to new replies.