Display Event Custom Field in WooCommerce Templates

Home Forums Ticket Products Event Tickets Plus Display Event Custom Field in WooCommerce Templates

  • This topic has 0 replies, 2 voices, and was last updated 8 years ago by Joe.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1482670
    Joe
    Participant

    Hi there,

    We have a client with several Events that also have a range of Tickets assigned.

    They would like a Custom Event Field (external URL) to be displayed on the WooCommerce Order Confirmation page and email once a related ticket is purchased.

    How would we obtain the relevant Event Custom field data once the ticket purchase has been processed by WooCommerce?
    Is there a meta link or something we can use to obtain this info? I imagine there has to be some connection..

    I’ve had a look through your support and tried using:

    <?php
    $tribe_custom_fields = tribe_get_custom_fields();
    if($tribe_custom_fields) {
    var_dump($tribe_custom_fields);
    }
    ?>

    But this returns an empty array.. I feel like we might be missing a step?

    I’ve also attached a screenshot showing the custom field that was created in the back-end.

    Any help you can offer would be greatly appreciated.

    Cheers,
    Swim

    #1482671
    Joe
    Participant

    Quick update, we’ve managed to get the following working:

    <?php 
    	$order = wc_get_order( $order_id );
    	$items = $order->get_items();
    
    	foreach ( $items as $item ) {
    		$product_id = $item->get_product_id();
    		$event_id = get_post_meta( $product_id , '_tribe_wooticket_for_event', true );
    	}
    
    	if($event_id) {
    		$event_fields = tribe_get_custom_fields($event_id);
    		echo '<div class="alert alert-info">';
    			if ($event_fields) {
    				$event_url = $event_fields['Vettrack URL'];
    				echo '<a href="'.$event_url.'" target="_blank" rel="noopener">Click here to enrol now</a>'; 
    			}
    		echo '</div>';
    	}
    ?>

    This returns the custom field we’re after. I just wonder if you can help us figure out a couple of things:

    • How should we make this work with multiple products? Is there a contingency we can put in place?
    • How can we echo the ‘URL’ custom field without it being an anchor tag? We just want the raw data

    Again I appreciate any help you can offer.

    Regards,
    Swim

    #1482672
    Joe
    Participant

    Bah I keep asking questions too early 😀

    We’ve just moved the if ($event_id) check into the foreach statement. Should work perfectly?
    It’ll display the custom field link for each product if applicable…

    Our question regarding the output of the URL Custom Field remains though..
    How would we output the raw data for this?

    Cheers,
    Swim

    #1483805
    Victor
    Member

    Hi Swim!

    Thanks for getting in touch with us!

    First, please let me note that we are fairly limited in how much support we can give for custom development questions like that.

    That said, we always like helping out and at least point users into the right direction as much possible.

    The code you posted in your first post should work depending on where you are executing it. I’m not really sure where you are adding that code, but as a reference, you can check our extension that adds event and attendee information to the WooCommerce order details > https://theeventscalendar.com/extensions/add-event-and-attendee-information-to-woocommerce-order-details/

    I hope that helps. 🙂

    Best,
    Victor

    #1504432
    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 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Display Event Custom Field in WooCommerce Templates’ is closed to new replies.