How to get event ID from Woocommerce Product in cart?

Home Forums Ticket Products Event Tickets Plus How to get event ID from Woocommerce Product in cart?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1059956
    David
    Participant

    Hi,

    I would like to loop through the items in a Woocommerce cart (this bit I can do no problem) and, for each ticket, find the associated event post ID. I can’t see any simple way to do this.
    Any ideas?

    Many thanks,
    Pete

    #1059971
    David
    Participant

    Never mind, I figured out a way to get what i needed.
    For anyone else that might need the event ID, here’s how;

    function get_tribe_event_ID_from_product($product_id) {
    	if ( class_exists( 'Tribe__Tickets_Plus__Commerce__WooCommerce__Main' )) {
    		$my_tribe = new Tribe__Tickets_Plus__Commerce__WooCommerce__Main();
    		$my_event_id = get_post_meta($product_id, $my_tribe->event_key, true);
    		return $my_event_id;
    	}
    }

    I’m using this to customise the checkout fields in WooCommerce based on ACF fields saved with the event and not the ticket itself.

    #1059983
    Brian
    Member

    I am glad to see you were able to figure it out and thanks for sharing the coding.

    I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.

    Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘How to get event ID from Woocommerce Product in cart?’ is closed to new replies.