Get Ticket Data by Event ID

Home Forums Ticket Products Event Tickets Plus Get Ticket Data by Event ID

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #911273
    masteagall
    Participant

    Hi Tribe,

    Sorry if this has been covered elsewhere. I truly have tried to find articles both in this support forum and elsewhere that cover this seemingly very basic thing, and I am not finding anything. The situation/question is:

    Let’s say I’m viewing an event, and that event has an ID of 80. And for that event, I have a couple of tickets attached to it, one which is an “Adult Price” ticket, and one that is a “Child’s Price” ticket. The question is: How do I get the ticket data that is attached to an event ID? A couple of many examples of how this could be useful are: having a nice banner at the top that says “Children only $10” (where the “$10” would be pulled from the ticket data). Or, another example: my own custom buttons elsewhere to create an add-to-cart-and-proceed-to-cart-view link, where the link is constructed using the ticket ID that is pulled from the ticket data.

    For the life of me this super simple thing is causing me to pull out my hair.

    Thanks in advance for your help,

    -M

    #912119
    George
    Participant

    Hey Andrew,

    Thanks for taking the time to search on the forums a bit! Sorry you weren’t able to find anything…
    fortunately, “Tickets” are basically just a type of “Product” within WooCommerce, and it’s not too complex to access all the tickets tied to a specific event.

    I should note that we only provide limited support for customizations, so while you’ll have to do most of the heavy lifting here, this should definitely help you get started in the right direction:

    • First get the active instance of the TribeWooTickets class, using TribeWooTickets::get_instance();

    • Then, use this class’s get_tickets_ids() method with your Event ID to get the attached tickets. You can view the function itself in the official WooCommerce Tickets documentation here → http://docs.tri.be/WooCommerce-Tickets/source-class-TribeWooTickets.html#_get_tickets_ids

    • Calling get_tickets_ids() should get you an array of IDs, each ID being a post ID for the specific ticket.

    For example, say an event whose ID is 123 has two levels of ticket: Adult, and Child’s. The titles for the tickets are “Adult Ticket” and “Child Ticket”, respectively. The following code would output those titles in H3 tags, using the ticket IDs:

    $woo_tickets = TribeWooTickets::get_instance();
    $ticket_ids  = $woo_tickets->get_tickets_ids( 123 );
    
    foreach ( $ticket_ids as $ticket_id ) {
        printf( '<h3>%s</h3>', get_the_title( $ticket_id ) );
    }

    Hopefully that helps! Basically, you can take that code and instead of just printing titles with $ticket_id, you can do whatever else you need or want to do.

    Play around with this, and definitely be sure to keep backups of all your code before and after making customizations.

    Let us know if this helps! 🙂
    George

    #912497
    masteagall
    Participant

    Hi George,

    Hey, thank you for the quick response! This is a huge help, and it works like a champ. I totally appreciate it. However, your response begs one more follow-up question:

    In your response I you use the function get_tickets_ids(); to output data. That’s great. However, when I try to search for more information on that function (in your support documentation or even on google) to see what I can find out about other existing functions that may be useful for retrieving ticket data, I don’t find anything. Where can I find more information about that function and any/all other related functions for tickets themselves? Am I just totally missing this list someplace obvious?

    I totally understand that you guys have a line that you practically can’t and shouldn’t cross in providing support (ie: no custom solutions), but admittedly I’m finding your documentation a bit tough to follow. And without easy to follow documentation I end up having to ask questions here. :\

    Looking forward to hearing back, and thanks again!

    Andrew M.

    #913595
    George
    Participant

    Hey Andrew,

    More can be learned about the function I mentioned specifically in the technical documentation I linked to earlier, which is here → http://docs.tri.be/WooCommerce-Tickets/source-class-TribeWooTickets.html#_get_tickets_ids

    The function itself is almost at the bottom of that file, around line 940 of the code it displays. If you can’t access this link or don’t find any code there to look through, let me know.

    When you mention that you’re trying to “find more information about other existing functions”, can you elaborate a bit on the specifics you need? I’ll then try to recommend something specific…but, in the meantime, here’s an overview of some great resources that might be helpful:

    • First is http://docs.tri.be/ – this is our technical documentation, and it lets you browse the code directly. This is the type of documentation I linked you to above, and really the only direct way to view the function I mentioned without opening the plugin’s files directly on your computer or something. If you’re curious about other specific functions, this is again the best place to look for them.

    • Other documentation can be found on our central support page here – https://theeventscalendar.com/support/ Check out the New User Primers and FAQs off of that page if you think they’ll be helpful, though in all honesty, there isn’t much technical info there that would help much if you’re trying to learn more about a specific function within the codebase.

    These are the main places to find documentation. If they help you at all, let me know, but if you’re still looking for “more information”, elaborate on what you’re curious about – are you looking for code examples? Alternative functions? If the former, the http://docs.tri.be pages are your best bet. If the latter, then unfortunately for the specific task you’re trying to do with WooCommerce Tickets I don’t think there are other functions that do this as directly as the methods I described in my first reply here.

    I’m really sorry for the long, wandering reply here – I just wanted to get as much info out as possible in hopes of helping you a bit further along. Let us know if anything here helps! 🙂

    Cheers,

    George

    #914561
    masteagall
    Participant

    Thanks for pointing me in the right direction. I… uh… I guess it didn’t occur to me to look specifically look at line 940, of public static TribeWooTickets’s get_instance( ), under TribeWooTickets entry under classes. :\

    I suppose that after working with other documentation ModernTribe has published that’s much better indexed, like what’s found at “http://docs.tri.be/Events-Calendar/&#8221;, we were thrown off and/or maybe had false expectations about indexing standards across products. For us, even just getting to see a simple and complete list of what functions are available is a HUGE help, and a monstrously big timesaver as we work through a project with a new plugin, rather than sifting through thousands of lines of code (ie: line 940 in one of many source code files for a seemingly basic function), then figuring out what that code does, and then making a list ourselves. Knowing what’s available up front gives you much better idea of what calls can be made, how swiftly you can accomplish something (if a function already exists for something you’re looking for), and what potential rests beneath the hood. And, going back to your asking, code samples and exemplary snippets would as well be excellent to have too.

    Anyway…
    Thanks again for your help and super-quick response. I do genuinely appreciate it. If anything else comes up we’ll be sure to give you guys a shout! 🙂

    Appreciative,

    Andrew

    #914563
    masteagall
    Participant

    .

    #914670
    George
    Participant

    Hey Andrew,

    Thanks for being cool and understanding the limitations of support we can provide for customizations. It’s nothing personal, and hopefully the resources we have available are enough for you and your team to get a great head start on stuff.

    I’ll close up this ticket, but yes, please do come back if other questions or concerns pop up – and don’t underestimate what you can find at https://theeventscalendar.com/support/ and http://docs.tri.be! With a little bit of sifting you’d be surprised how thorough some of the info is and how much you can piece together with a little experimentation. And backups. Please do not customize things without backups that you know you can restore from in case something goes awry.

    Cheers!
    George

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Get Ticket Data by Event ID’ is closed to new replies.