Home › Forums › Calendar Products › Events Calendar PRO › How to show total stock and
- This topic has 4 replies, 3 voices, and was last updated 8 years ago by Support Droid.
-
AuthorPosts
-
March 22, 2016 at 4:02 pm #1092653CesarParticipant
Hi guys,
Is there any code to show total stock in front-end?
Example,
echo tribe_events_count_available_tickets()
gives me the available tickets… I would like to know if there is an equivalent for total.Thank you.
March 23, 2016 at 2:25 pm #1093135BrookParticipantHowdy Cesar,
I would love to help you with this.
There is no single function that does this. However, it should be easy to create you own. I’d first start with by copying the source from the function that you quoted:
[php]
/**
* Counts the total number of tickets still available for sale for a
* specific event.
*
* @param null $event
*
* @return int
*/
function tribe_events_count_available_tickets( $event = null ) {
$count = 0;if ( null === ( $event = tribe_events_get_event( $event ) ) ) {
return 0;
}foreach ( Tribe__Tickets__Tickets::get_all_event_tickets( $event->ID ) as $ticket ) {
$count += $ticket->stock();
}return $count;
}[/php]In there you will notice it is counting theĀ $ticket->stock(); integer. Well there are a coulpleĀ other options available:
$ticket->qty_sold(); $ticket->qty_pending();
If you want it to include sold tickets as well as pending, and of course the stock available, then I would count all three of those. Just rename the function, add each of them to the total, and you’re golden.
Does that all make sense? Will that work for you? Please let me know.
Cheers!
– Brook
March 29, 2016 at 2:35 pm #1095641CesarParticipantThis reply is private.
March 30, 2016 at 3:16 pm #1096136BrookParticipantHowdy Cesar,
Exactly! Just define those variables, and then sum the three of them up.
Cheers!
– Brook
April 14, 2016 at 9:35 am #1102535Support DroidKeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘How to show total stock and’ is closed to new replies.