Support

Home Forums Event Espresso Premium Adding a custom field in Event Tickets & Datetimes

Adding a custom field in Event Tickets & Datetimes

Posted: July 23, 2015 at 8:47 am


Eversion Systems

July 23, 2015 at 8:47 am

I’ve added a custom field to the metabox and I can get the data to successfully save but I can’t work out how to display the data using the filter FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args to add my extra field to $template_args so it’s available to display. I need to call the function get_extra_meta() but I don’t seem to have an object available in the filter to call that function from.

	//This is used to display the value of the SKU
	add_filter( 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', 'es_display_tkt_SKU', 10, 7);
		
	function es_display_tkt_SKU($template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets ) {
		//$TKT = $template_args['TKT_ID'];
		$template_args['TKT_SKU'] = $ticket->get_extra_meta( 'SKU', true );
		
		return $template_args;
	}


Dean

July 24, 2015 at 12:29 am

Hi,

If the data has been saved as post meta, why not do something like:

global $post;
$template_args['TKT_SKU'] = get_post_meta( $post->ID, 'key_1', true );

https://developer.wordpress.org/reference/functions/get_post_meta/


Eversion Systems

July 24, 2015 at 1:09 am

It’s been saved to the event espresso meta tables not into post meta data table.


Dean

July 24, 2015 at 1:50 am

Thanks for the clarification.

I took a look but I couldn’t make sense of it. I’ll ping a developer and ask them to weigh in on this. Please note, the devs work on US time zones.


Eversion Systems

July 24, 2015 at 3:30 am

Ok thanks. I think it should be straight forward but I don’t know what object to instantiate…


Darren Ethier

July 24, 2015 at 5:16 am

Hi,

The filter you are using filters an array of key/value pairs that are then converted to what we call “Template Arguments” that are then parsed for content when displaying the /caffeinated/admin/new/pricing/templates/event_tickets_datetime_ticket_row.template.php template.

If you open that template file, you’ll see that there are a number of actions there that you can use to hook in the display of data.

For instance there is an action that allows one to add something after the ticket row description field: AHEE__event_tickets_datetime_ticket_row_template_after_desc and it has two arguments passed to the callback, $tkt_row and $TKT_ID.

You can instantiate the ticket object from the ticket ID in your callback by using our model system like this:

$ticket = EEM_Ticket::instance()->get_one_by_ID( $TKT_ID );
$extra_meta = $ticket->get_extra_meta( 'meta_key', true );

Hope that helps with what you want to do?


Eversion Systems

July 24, 2015 at 9:26 am

I’ve worked it out. Here is the code that works, my issue was I had to check that each ticket returned in the loop had a ticket ID greater than zero otherwise it would generate a fatal error. Thanks for your help!

//This is used to display the value of the SKU
	add_filter( 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', 'es_display_tkt_SKU', 10, 7);
		
	function es_display_tkt_SKU($template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets ) {
		
		$TKT_ID = $template_args['TKT_ID'];
		
		if($TKT_ID > 0) {
			//$ticket = EEM_Ticket::instance()->get_one_by_ID( $TKT_ID );
			$template_args['TKT_SKU'] = $ticket->get_extra_meta( 'SKU', true );
		}
		
		return $template_args;
	}


Darren Ethier

July 24, 2015 at 9:29 am

Another trick for validating the ticket is do do this:

$ticket = EEM_Ticket::instance()->get_one_by_ID( $tktID );
if ( $ticket instanceof EE_Ticket ) {
   ///do stuff with $ticket
}


Eversion Systems

July 26, 2015 at 6:54 pm

Ah brilliant that’s exactly what I was looking for thanks!

The support post ‘Adding a custom field in Event Tickets & Datetimes’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Eversion Systems 4 years, 1 month ago ago

Topic Tags

Notifications

This topic is: resolved
Do NOT follow this link or you will be banned from the site!