Retrieve Event ID from Ticket ID

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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1022840
    Wee Hang
    Participant

    Hi,

    In regards to the question posted at

    https://theeventscalendar.com/support/forums/topic/get-ticket-data-by-event-id/

    I would like to know is there a way to retrieve Event ID from Ticket ID?

    #1023377
    George
    Participant

    Hey @Wee Hang,

    The current method for getting the Event ID from a ticket’s ID is to use the get_event_for_ticket method on the Tribe__Events__Tickets__Woo__Main class.

    So, for example, let’s say you have a ticket ID stored in a variable $ticket_id – you could get the event ID like this:


    $tribe_woo = Tribe__Events__Tickets__Woo__Main::get_instance();
    $ticket_product = class_exists( 'WC_Product_Simple' ) ? new WC_Product_Simple( $ticket_id ) : new WC_Product( $ticket_id );

    $event = $tribe_woo->get_event_for_ticket( $ticket_product );

    At this point in the code above, $event is now the WP_Post object for the event. So to get the ID of it, just call $event->ID.

    Cheers!
    George

    #1024232
    Wee Hang
    Participant

    Hi George,

    Thanks for the reply. So I have replaced the ticketID with the productID because as I have understood it, its the same right? But I am not able to retrieve the information of that said event but rather the result return is the product details in array. Did I miss out it somewhere?

    $tribe_woo = Tribe__Events__Tickets__Woo__Main::get_instance();
    $ticket_product = class_exists( ‘WC_Product_Simple’ ) ? new WC_Product_Simple( $cart_item[“data”]->id ) : new WC_Product( $cart_item[“data”]->id );

    $event = $tribe_woo->get_event_for_ticket( $ticket_product );

    #1024525
    George
    Participant

    Hi @Wee,

    I’m not quite sure about the results you claim to be getting – sorry if things aren’t working right here! They do for me though…I would recommend adding this bit of code right after the last line of the code I wrote above:


    var_dump( $event );

    Then view the front-end of your site again; what is the output of this function for you? You can copy and paste the whole output into a paste on Pastebin.com and share a link to that paste here, I’ll take a look…

    Thanks!
    George

    #1024851
    Wee Hang
    Participant

    I’m looking at bool(false) as the result.
    I am putting this code at woocommerce’s plugin in cart’s page. Not sure if it will affect or changes anything.

    #1025418
    George
    Participant

    The problem is likely indeed related to something with this value: $cart_item['data']->id

    I’d recommend just working backwards on this – var_dump all of the other values at work here, like $cart_item['data']->id itself, and $ticket_product, and see if the ID indeed corresponds to a ticket in the admin and all that. I wish I had more insight to offer here; but unfortunately I don’t 🙁

    I hope this helps!
    George

    #1075608
    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 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Retrieve Event ID from Ticket ID’ is closed to new replies.