How to show total stock and

Home Forums Calendar Products Events Calendar PRO How to show total stock and

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1092653
    Cesar
    Participant

    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.

    #1093135
    Brook
    Participant

    Howdy 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

    #1095641
    Cesar
    Participant

    This reply is private.

    #1096136
    Brook
    Participant

    Howdy Cesar,

    Exactly! Just define those variables, and then sum the three of them up.

    Cheers!

    – Brook

    #1102535
    Support Droid
    Keymaster

    This 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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘How to show total stock and’ is closed to new replies.