Home › Forums › Ticket Products › Event Tickets Plus › Retrieve Event ID from Ticket ID
- This topic has 6 replies, 3 voices, and was last updated 8 years, 1 month ago by Support Droid.
-
AuthorPosts
-
November 7, 2015 at 7:38 am #1022840Wee HangParticipant
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?
November 9, 2015 at 11:30 am #1023377GeorgeParticipantHey @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!
GeorgeNovember 11, 2015 at 8:39 am #1024232Wee HangParticipantHi 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 );
November 12, 2015 at 5:07 am #1024525GeorgeParticipantHi @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!
GeorgeNovember 12, 2015 at 11:23 am #1024851Wee HangParticipantI’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.November 13, 2015 at 11:07 am #1025418GeorgeParticipantThe 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!
GeorgeFebruary 18, 2016 at 8:31 am #1075608Support 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 ‘Retrieve Event ID from Ticket ID’ is closed to new replies.