Home › Forums › Ticket Products › Event Tickets Plus › Get attendee ids from order_id
- This topic has 5 replies, 4 voices, and was last updated 9 years, 9 months ago by
Dylan.
-
AuthorPosts
-
July 14, 2016 at 3:09 pm #1139959
Dylan
ParticipantI’m sure this is simple but I couldn’t seem to find an example of this in the plugins code.
Is there a way to get the post id for the attendee post by using the woocommerce order_id.
Just looking for a way to hook into the order complete action and get the attendee ids from the order.
July 15, 2016 at 6:29 am #1140247Nico
MemberHi Dylan,
Thanks for getting in touch with us! Interesting question here…
Take a look to the function below, I modified the code of a similar snippet. It will extract event_ids from an order and then extract all attendee info for those events:
/* Return all attendees for events in a WooCommerce order */
function tribe_order_extract_attendees ( $order_id ) {$order = new WC_Order ( $order_id );
$line_items = $order->get_items( apply_filters( 'woocommerce_admin_order_item_types', 'line_item' ) );
$product_ids = array();
$event_objects = array();
$attendees = array();if ( ! is_array( $line_items ) || empty( $line_items ) ) {
return $attendees;
}foreach ( $line_items as $line_item ) {
$product_id = absint( $line_item['item_meta']['_product_id'][0] );if ( ! $product_id || in_array( $product_id, $product_ids ) ) {
continue;
}$event_object = tribe_events_get_ticket_event( $product_id );
if ( ! empty( $event_object ) ) {
$event_objects[] = $event_object;
}
}foreach ( $event_objects as $event_object ) {
$tickets = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
$event_attendees = $tickets->get_event_attendees( $event_object->ID );
$attendees = array_merge ( $attendees, $event_attendees );
}return $attendees;
}
Is this what you are looking for? If not please let me know about it and we can tweak the function code.
Best,
NicoJuly 15, 2016 at 9:20 pm #1140644Dylan
ParticipantThat isn’t exactly what I was trying to do. I was just trying to get the different attendee post ids after an order so that I can use it to use this code to retrieve their meta values.
$metas = get_post_meta( $attendee, ‘_tribe_tickets_meta’, TRUE );
I am using the action woocommerce_new_order to hook into so I want to be able to get the different $attendee values from the $order_id to access the _tribe_tickets_meta
I may be making that more complex than it needs to be but that was the only way I could think of getting those meta values from the order.
July 18, 2016 at 4:47 am #1140977Nico
MemberThanks for the follow-up Dylan! No quite sure what’s the final goal of this customization but check this updated version of the snippet:
/* Return all attendees for events in a WooCommerce order */
function tribe_order_extract_attendees ( $order_id ) {$order = new WC_Order ( $order_id );
$line_items = $order->get_items( apply_filters( 'woocommerce_admin_order_item_types', 'line_item' ) );
$product_ids = array();
$event_objects = array();
$attendees = array();if ( ! is_array( $line_items ) || empty( $line_items ) ) {
return $attendees;
}foreach ( $line_items as $line_item ) {
$product_id = absint( $line_item['item_meta']['_product_id'][0] );if ( ! $product_id || in_array( $product_id, $product_ids ) ) {
continue;
}$event_object = tribe_events_get_ticket_event( $product_id );
if ( ! empty( $event_object ) ) {
$event_objects[] = $event_object;
}
}foreach ( $event_objects as $event_object ) {
$tickets = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
$event_attendees = $tickets->get_event_attendees( $event_object->ID );
foreach ( $event_attendees as $attendee ) {
//echo ' --- ' . $attendee['order_id'] . ' *** ' . $order_id;
if ( intval($attendee['order_id']) != $order_id ) continue;
$attendees[] = $attendee;
// use the code below to just get attenddee ids
// $attendees[] = $attendee['attendee_id'];
}
}return $attendees;
}
Now it will return the attendee info for the order. If you only needs the attendees IDs use the commented line in the function instead.
Best,
NicoAugust 9, 2016 at 9:35 am #1149466Support Droid
KeymasterThis 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 ‘Get attendee ids from order_id’ is closed to new replies.
