Skip to content

Instantly share code, notes, and snippets.

@lorenzocaum
Last active January 31, 2019 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzocaum/ef6afefd07c9c5f6f681 to your computer and use it in GitHub Desktop.
Save lorenzocaum/ef6afefd07c9c5f6f681 to your computer and use it in GitHub Desktop.
Edit the Events Table View Template Add-on for Event Espresso 4 to show the first ticket price for each event in a new Starting From column

This can be done by relocating one of the templates and making a change to some lines of code. This will ensure that your customization is not lost on a software update.

The support team at Event Espresso will never recommend you edit any core plugin or add-on files directly.

Here are the steps:

  1. Login to your WordPress root with your preferred SFTP or FTP client. Filezilla and Cyberduck are free options. On a Mac? Try Transmit

  2. Browse to this location:

/wp-content/plugins/eea-events-table-view-template/templates

You'll see two files there:

espresso-events-table-template-toggle.template.php

espresso-events-table-template.template.php

  1. Download a copy of the espresso-events-table-template.template.php file to your computer

  2. Now browse to your child theme:

/wp-content/themes/name-of-your-child-theme

Not using a child theme? A child theme allows you to customize your WordPress theme without losing customizations when you update your theme through WP. Here is how to setup a child theme.

  1. Upload the the file that you downloaded earlier to the location above

  2. Open the espresso-events-table-template.template.php file for editing

At about line 46 you'll see this line of code:

	<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
  1. Replace the line above with this:
	<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
	<th class="th-group"><?php _e('Starting From','event_espresso'); ?></th>
  1. At about line 53, you'll see this line of code:
			<td colspan="4">
  1. Replace it with this:
			<td colspan="5">
  1. At about line 99 you'll see this line of code:
		$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );

		$datetime = end( $datetimes );

  1. Replace it with this:
		$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
		
		$datetime = end( $datetimes );
		
		if ( ! $event->is_sold_out() ) {
			
			// grab array of EE_Ticket objects for event
			$tickets = EEH_Event_View::event_tickets_available( $post->ID );
			
			// grab first ticket from array
			$ticket = reset( $tickets );
			//check if the ticket is free, if set the ticket price to 'Free'
			if ( $ticket instanceof EE_Ticket ) {
				$ticket_price = $ticket->pretty_price();
				$ticket_price_data_value = $ticket->price();
				$ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
			}			
			
			//Get the remaining ticket values for the next datetime.
			$tickets_remaining = $datetime->tickets_remaining() === EE_INF ? __('Unlimited','event_espresso') : $datetime->tickets_remaining();
		} else {
			
			//The event is sold out, set the ticket price to 'N/A'
			$ticket_price = __( 'N/A', 'event_espresso');
		}
  1. At about line 112 (after edit above about line 138) you'll see this line of code:
				<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo $datetime->get_raw( 'DTT_EVT_start' ); ?>"><?php echo $startdate; ?></td>

  1. Replace it with this:
			<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo $datetime->get_raw( 'DTT_EVT_start' ); ?>"><?php echo $startdate; ?></td>
			<td class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $ticket_price; ?></td>

Then save changes.

In the first code change, we are adding a new column with a column heading of Starting From and adjusting the column value. In the second code change, we adding some supporting coding to get the ticket pricing. In the third code change we are then displaying the price for the ticket in the new column.

If an event is free as in the ticket is zero (0) then the word "Free" will show instead of a numeric value. You can change that verbiage by changing the word Free to something else during step 11. If an event is sold out, then N/A will show for the event price.

@ErinK
Copy link

ErinK commented Mar 14, 2016

I did not see the code listed on #8 of the instructions. I saw this:

$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
$datetime = end( $datetimes );

I placed the next bit of code below there and it worked for me.

I'm using EE4 v.4.8.35.p with the Event Table Add-on v.1.3.3.p

In any case, thanks for posting this. Just what I needed.

Erin

@joshfeck
Copy link

If you want to show all of the prices (not just one of the ticket prices) you can make an adjustment to the code in step 11. This part can be removed:

// grab first ticket from array
$ticket = reset( $tickets );
//check if the ticket is free, if set the ticket price to 'Free'
if ( $ticket instanceof EE_Ticket ) {
    $ticket_price = $ticket->pretty_price();
    $ticket_price_data_value = $ticket->price();
    $ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
}

and replaced with this:

$ticket_price = '<ul>';
if ( is_array( $tickets ) ) {
    foreach ($tickets as $ticket ) {
        if ( $ticket instanceof EE_Ticket ) {
            $ticket_price .= '<li>' . $ticket->pretty_price() . '</li>';
        }
    }
} else {
    if ( $tickets instanceof EE_Ticket ) {
        $ticket_price .= '<li>' . $tickets->pretty_price() . '</li>';
    }
}
$ticket_price .= '</ul>';

@whataboutchris
Copy link

whataboutchris commented Jul 10, 2018

Hey all! I know this i an old post but maybe you can still help.

I tried following some of the instructions above , but the code has changed since. I got this far...

	$datetime = reset( $datetimes );
        if ($datetime instanceof EE_Datetime) {
        ?>
		<tr class="espresso-table-row <?php echo $category_slugs; ?>">
			<td class="event_title event-<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></td>
			<?php if( $show_venues ) { ?>
				<td class="venue_title event-<?php echo $post->ID; ?>"><?php espresso_venue_name( NULL, FALSE ); ?></td>
			<?php } ?>
			
			<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo $datetime->get_raw( 'DTT_EVT_start' ); ?>"><?php echo $startdate; ?></td>
			
			<td class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $ticket_price; ?></td>
			
				<ul class="ee-table-view-datetime-list">
					<?php
						// Loop over each datetime we have pulled from the database and output
						foreach ($datetimes as $datetime) {
						?>
							<li class="datetime-id-<?php echo $datetime->ID(); ?>">
								<?php echo date_i18n(  $date_format . ' ' . $time_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) ); ?>
							</li>
					<?php
						//end foreach $datetimes
						}
					?>
				</ul>
			</td>
			<td class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
		</tr>

The date falls outside of the table. See here: https://d.pr/i/yQkJOA

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment