Home › Forums › Ticket Products › Event Tickets Plus › Displaying remaining stock in related events
- This topic has 5 replies, 3 voices, and was last updated 8 years, 5 months ago by Brook.
-
AuthorPosts
-
November 20, 2015 at 2:58 am #1028401ChrisParticipant
Hi – using the following function found on here I’m wanting to output the remaining stock level into the ‘Related Events’ section at the bottom of each single event page. I’ve tried modifying as it as standard just outputs the stock level of the current product page onto each related event.
However it doesn’t work – Closest I can get is a list of all ticket stock! Any guidance would be much appreciated…
function displaying_stock_information() {
`$post_id = get_the_id();
if ( Tribe__Events__Main::POSTTYPE !== get_post_type( $post_id ) ) {
return;
}
$Woo__Tickets = Tribe__Events__Tickets__Woo__Main::get_instance();
$ticket_ids = $Woo__Tickets->get_tickets_ids( $post_id );if ( is_array( $ticket_ids ) ) {
foreach ( $ticket_ids as $ticket_id ) {
$ticket = $Woo__Tickets->get_ticket( $post_id, $ticket_id );
$html .= sprintf( ‘<dt>Places available:</dt><dd>%s</dd>’, $ticket->stock );
// to show ticket name also: $html .= sprintf( ‘- %s tickets remaining: %s
‘, $ticket->name, $ticket->stock );
}if ( $ticket->stock > 0 ) { // if all tickets sold or no tickets
echo $html;
} else {
echo ‘<dt>Places available:</dt><dd>COURSE SOLD OUT</dd>’;
}
}}`
November 20, 2015 at 10:12 am #1028696GeoffMemberHey there, Chris!
Would theĀ tribe_events_count_available_tickets() function be an easier way to display the number of remaining tickets? That’s where I would suggest starting.
Let me know if that helps and I’d be happy to answer any follow-up questions as best I can.
Cheers!
GeoffNovember 21, 2015 at 4:53 am #1028834ChrisParticipantBrilliant! sorted with a bit of tweaking, Many thanks.
Here’s the code in case anyone else needs it:
function tribe_events_count_available_related_tickets( $event = null ) { $count = 0; if ( null === ( $event = tribe_events_get_event( $event ) ) ) { return 0; } foreach ( Tribe__Events__Tickets__Tickets::get_all_event_tickets( $event->ID ) as $ticket ) { $count += $ticket->stock; $html .= sprintf( '<dt><strong>Places available:</strong></dt><dd>%s</dd>', $count ); $html2 .= sprintf( '<dd><strong>COURSE SOLD OUT</strong></dd>', $ticket->stock ); } if ( $ticket->stock > 0 ) { // if all tickets sold or no tickets echo $html; } if ( $count < 1 ) { echo '<dd><strong>COURSE SOLD OUT</strong></dd>'; } }
November 21, 2015 at 4:54 am #1028835ChrisParticipantTa
November 21, 2015 at 10:53 am #1029055ChrisParticipantForgot the last!
This is the one:
function tribe_events_count_available_related_tickets( $event = null ) { $count = 0; if ( null === ( $event = tribe_events_get_event( $event ) ) ) { return 0; } foreach ( Tribe__Events__Tickets__Tickets::get_all_event_tickets( $event->ID ) as $ticket ) { $count += $ticket->stock; $html .= sprintf( '<dd><strong>Places available: </strong>%s</dd>', $count ); } if ( $ticket->stock > 0 ) { echo $html; } if ( $count < 1 ) { // if all tickets sold or no tickets echo '<dd><strong>COURSE SOLD OUT</strong></dd>'; } }
November 24, 2015 at 4:42 pm #1030437BrookParticipantThank you for sharing your solution! That’s very awesome of you.
I am going to archive this topic now. It will be available for all who want to refer to your work. Cheers!
– Brook -
AuthorPosts
- The topic ‘Displaying remaining stock in related events’ is closed to new replies.