_tribe_tickets_attendee_user_id meta is being set to "0"

Home Forums Ticket Products Event Tickets Plus _tribe_tickets_attendee_user_id meta is being set to "0"

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1243594
    somatic
    Participant

    This bug has been reported earlier on this thread, but it was closed (without being resolved) due to inactivity.

    I am attempting to write a query to show a customer the various events they have purchased a ticket for, and I’m querying all the post_type “tribe_wootickets” and looking for a matching user ID in the post_meta. But this particular key (which would be very helpful) is set to “0”.

    My best guess about why it might not be working is that this is a new customer (who is not logged in while shopping), and I have woocommerce set to create a user account for that customer upon checkout. If it is an existing logged-in user who purchases a ticket, the _tribe_tickets_attendee_user_id meta value is being set properly.

    If this is the case, I would strongly suggest you incorporate some method of updating that meta_value after the order has gone through and you are able to retrieve the fresh new user ID that has been associated with the order. Otherwise this meta_key is simply not a reliable source of information.

    #1243616
    somatic
    Participant

    I found another forum thread that appears related — I didn’t even know the shortcode [tribe-user-event-confirmations] existed!

    But the shortcode is not working for me either, and I’m betting it’s because it builds its results using an SQL query that calls the same _tribe_tickets_attendee_user_id meta_key (which is set to zero)

    I even used the handy code provided by Nico in that same thread, to get a handle on what the shortcode is doing, but it’s depending on that same meta_key which is useless if the customer *was not logged in when they purchased*, even if they have an account as a result of the purchase.

    #1245138
    Barry
    Member

    Hi Somatic,

    Thanks for contacting us 🙂

    I’d like to double check that I’m understanding the problem correctly, as I seem unable to replicate. Here’s what I tried:

    • I enabled the creation of accounts during checkout
    • I ensured the requirement for users to be logged in before they can purchase tickets was disabled
    • As an unauthenticated user, I purchased a ticket and created a new account during checkout
    • The resulting attendee post was associated with the new user account (‘_tribe_tickets_attendee_user_id’ was not zero)

    Am I missing any steps or misunderstanding anything needed to replicate the problem?

    Thanks!

    #1245592
    somatic
    Participant

    Those would seem to be the appropriate steps, yes — so if you’re not getting the same results then I’m going to have to dig deeper… was simply a guess that account creation at checkout would be the cause.

    I managed to code a workaround to accomplish the same goal of fetching all the events a user has registered for, not sure if I’ve got the time to troubleshoot the cause of _tribe_tickets_attendee_user_id = 0

    // get this customer's orders newest > oldest
    $customer_orders = get_posts( array(
    	'numberposts' => -1,
    	'meta_key'    => '_customer_user',
    	'meta_value'  => get_current_user_id(),
    	'post_type'   => wc_get_order_types( 'view-orders' ),
    	'post_status' => array_keys( wc_get_order_statuses() ),
    	'orderby'	  => 'date',
    	'order'       => 'DESC',
    	'fields'	  => 'ids'
    ) );
    
    // event container
    $my_events = array();
    
    foreach ( $customer_orders as $customer_order ) {
    	// lookup order
    	$order = new WC_Order( $customer_order );
    	// check each product in this order to see if it's an event ticket, if so, return the event's Post Object
    	foreach ( $order->get_items() as $key => $lineItem ) {
    		$maybe = tribe_events_get_ticket_event( $lineItem['product_id'] );
    		if ( !empty( $maybe ) ) {
    			$my_events[] = $maybe->ID;
    		}
    	}
    }
    
    return $my_events;

    that tribe_events_get_ticket_event() function is handy for scanning orders for tickets, as it returns the Event the ticket is for, otherwise false.

    #1245936
    Barry
    Member

    That looks like a decent approach (though it’s a shame it’s necessary) — if you do hit any insights that would help us to see and replicate the source problem though, definitely let us know (and to that end, we’ll leave this support topic open for the time being).

    #1256468
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘_tribe_tickets_attendee_user_id meta is being set to "0"’ is closed to new replies.