Getting Event from Ticket ID

Home Forums Ticket Products Event Tickets Plus Getting Event from Ticket ID

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #888041
    Joshua Hay
    Participant

    Hey guys,

    I’m doing some custom code to give admins a list of attendee (meta) information. This is really easy to work with in the WooTickets templates having the ticket object supplied, but I am wondering how I could create a ticket object based on the product (ticket) ID alone. I might be having a brain fart here, but could you guys give me a pointer?

    Any help would be much appreciated.

    #888445
    George
    Participant

    Hello, @hellowebsites 🙂

    We only provide limited support for custom coding and such, but if you could post your custom code somewhere (in a site like Pastebin, or ideally into a “Gist” at http://gist.github.com) so we could take a look at it, we might be able to offer some insight here.

    Apologies for such a terse reply – it’s hard to say much without seeing your custom code for context here.

    Let us know if you can post the code somewhere, and we’ll be happy to take a closer look and see what insights (if any) we can provide here.
    Thanks!
    George

    #890897
    Joshua Hay
    Participant

    https://gist.github.com/anonymous/114df1b406c55be263c5

    Basically, I was just wondering if there’s a way to create a Ticket object or other way to grab the Event using a ticket ID. Any help would be great, thanks.

    #891257
    George
    Participant

    Hey Joshua,

    Thanks for your patience with this issue, and I’m sorry to request even more code from you – but in the Gist you’ve shared here, you mention a function you’ve made called “workshop_attendee_info()”.

    Can you paste this function in its entirety to another Gist? This may seem tedious, but if you can access $ticket[‘order_id’] within your code but not $ticket[‘event_id’] in your code, I don’t want to speculate on why that’s not the case. Seeing your function in full will help us decipher this problem.

    Thanks,
    George

    #892129
    Joshua Hay
    Participant

    No worries, I appreciate the patience as well. Here it is:

    https://gist.github.com/anonymous/8630272906cc46642199

    #892714
    George
    Participant

    Hey Joshua,

    While we won’t be able to help further build out your functions and such, I did a little digging here and indeed found where the ticket IDs reside when you call a WooCommerce order.

    Basically, you’re almost there with your existing code. To get an array of the ticket(s) bought at checkout in a given order, simply grab the order by ID with the WC_Order class like you’re already grabbing. You’re grabbing the order object and storing it in a variable called “$order”, so that’s what I’ll use too in my examples here:

    Once you have the WC_Order stored in $order, you can then use $order->get_items() to get an array of the tickets purchased at checkout. Within this array, you can find the ticket IDs. They’re quite nested – if you get the first element in the array, for example, to get its ID you’ll have to go to a child array called ‘item_meta’, then to another child array called ‘_product_id’, and then get whichever ID number from that array that matches the ticket you’re trying to get.

    Sorry if that’s a bit confusing. For a quick example, using your code in your Gist above this reply, you could get the ticket ID with the following code:

    $ticket_id =  $items[1]['item_meta']['_product_id'][0];

    Note that I’m using the $items variable, because in your function this is the variable you set equal to $order->get_items()`.

    If this is still a big pain for you, sorry Joshua! But have hope, you’re very very close to where you need to be. If my exact code doesn’t work for you, the best thing I could recommend at this point would be to simply var_dump() or use print_r() on your $orders->get_items() instances to see what sort of information they return. If you’re not familiar with var_dump() or print_r(), definitely find some info about them on the Web and use them for more insights here.

    Let me know if this is helpful at all, or if you have any followup questions – this is about as far as we can go with customization-specific code, so if you’re all set, I’ll close up this ticket.

    Thanks Joshua!

    – George

    #892717
    Joshua Hay
    Participant

    This is awesome, thanks so much!

    #892736
    George
    Participant

    No worries Joshua! While you might not have had time to actually test out my code so far, I’ll go ahead and mark my answer there as the official answer on this thread.

    I’ll also close up this thread, but if you have other issues or questions don’t hesitate to come back and open a new thread if need be.

    Oh, and one last tip: be sure to keep backups of all custom code like this, and do your best to not modify any core files within Events Calendar, Events Pro, the WooCommerce Tickets add-on, or WooCommerce itself.

    Best of luck with your project!
    George

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Getting Event from Ticket ID’ is closed to new replies.