Event Tickets Plus does a great job adding tickets to your events and selling them through WooCommerce. We’ve come across instances, however, where having the name of the event in the cart next to the ticket name would come in handy. For example, what if there are multiple tickets being purchased for different events but each ticket is called “General Admission”? That could become a confusing user experience.

Here is how a ticket currently appears when added to the WooCommerce cart:

kb-wootickets-cart

Now, imagine several tickets called “General Admission” in there. We will see the prices but won’t know exactly which tickets correlate with which event we’re purchasing tickets to. That wouldn’t be optimal.

To dispel confusion, we can add the event name after the ticket title. Now the text in the Product column tells the user more about the ticket they are buying:

kb-wootickets-cart-withtitle

It’s a minor detail, but these things can add up to a better user experience that makes your visitors happier during the checkout process. And happy visitors makes a happy website.

To do this on your site, add the snippet below to your theme’s functions.php file:

<?php
/**
 * Example for adding event data to WooCommerce checkout for Events Calendar tickets.
 * @link https://theeventscalendar.com/support/forums/topic/event-title-and-date-in-cart/
 */
add_filter( 'woocommerce_cart_item_name', 'woocommerce_cart_item_name_event_title', 10, 3 );

function woocommerce_cart_item_name_event_title( $title, $values, $cart_item_key ) {
	$ticket_meta = get_post_meta( $values['product_id'] );

	// Only do if ticket product
	if ( array_key_exists( '_tribe_wooticket_for_event', $ticket_meta ) ) {
		$event_id = absint( $ticket_meta[ '_tribe_wooticket_for_event' ][0] );

		if ( $event_id ) {
			$title = sprintf( '%s for <a href="%s" target="_blank"><strong>%s</strong></a>', $title, get_permalink( $event_id ), get_the_title( $event_id ) );
		}
	}

	return $title;
}