Support

Home Forums Event Espresso Premium display registrations for multiple attendees in ESPRESSO_MY_EVENTS shortcode

display registrations for multiple attendees in ESPRESSO_MY_EVENTS shortcode

Posted: November 21, 2018 at 4:39 am

Viewing 8 reply threads


lhammond

November 21, 2018 at 4:39 am

I would like to display all registrations for a family, so I’m looking for a way to pass a list of related attendee IDs and then retrieve the events and display them together all in one table, sortable by attendee or by event name. Can I edit the ESPRESSO_MY_EVENTS shortcode template (loop-espresso_my_events-event_section.template.php) to essentially loop over all the registrations for the current user but also repeat for a list of att_ids I provide? Or do I need to modify or extend the shortcode itself?

If I need to modify the shortcode, I see there are multiple files for the same shortcode, so I’m confused about which one to edit, and of course, I don’t want to overwrite the actual add-on code. So can I do it with hooks from my own custom plugin function?

Also, I would like to show the following additional columns for the MY_EVENTS output:
– attendee name
– start date (separate from class time)
– class time (separate from start date)
– days of week class meets (we have this stored in a meta field of the event)

Can you help me with a code snippet to retrieve that information?

Thanks!


lhammond

November 22, 2018 at 4:11 am

I have been reading the support posts and documentation, and I am wondering if I can somehow achieve the changes I need to make with a filter hook?

Also, will any of the helper templates point me in the right direction? I don’t see an EEH_Registrations.helper.php, but maybe a combination of the EEH_Event_View and other helpers will somehow? I will go start reading the code…


Tony

  • Support Staff

November 22, 2018 at 5:30 am

Hi there,

Can I edit the ESPRESSO_MY_EVENTS shortcode template (loop-espresso_my_events-event_section.template.php) to essentially loop over all the registrations for the current user but also repeat for a list of att_ids I provide?

With regards to the actual template file itself, yes you can, most template files can simply be placed within your themes root directory to override the default template file. If you’re not using a custom theme specifically for your site, we recommend creating a child theme and placing them within that.

Looping over the registrations of the current user and the add_id’s you provide is also possible, you’ll basically need to re-pull all of the registration you need from the database and override what the shortcode has already done for you.

Note that it is possible to pull registrations for known ATT_ID’s using our model system, have you read through any of the documentation for the models? If not, take a look here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

Generally, we don’t provide snippets for customizations but we can help point you in the right direction, for example you can use the models like this:

$registrations = EEM_Registration::instance()->get_all(
	array(
		array(
			'ATT_ID' => array( 
				'IN', array(
					918, 
					234 
				)	
			)
		)
	)
);

Which would pull in all of the registrations for ATT_ID 918 and 234…. BUT if you’re looking to pull registrations for a specific event and known ATT_ID’s, you use a completely different model, so understanding how our model system works is important.

Or do I need to modify or extend the shortcode itself? If I need to modify the shortcode, I see there are multiple files for the same shortcode, so I’m confused about which one to edit, and of course, I don’t want to overwrite the actual add-on code.

Template files or others?

Whilst it may not appear so at first glance, the shortcode is actually pulling in a lot of data and covering a lot of different setups at once, which is why it breaks everything down it multiple templates (to help users modify the specific sections they need to).

It depends on the exact changes you want to make as to how you do it.

Also, I would like to show the following additional columns for the MY_EVENTS output:
– attendee name
– start date (separate from class time)
– class time (separate from start date)
– days of week class meets (we have this stored in a meta field of the event)

Are you using the default event_section template or simple_list_table? (If you don’t know it’ll be the event_section, as you have to add a shortcode parameter to load the simple_list_table.

Within which section, I’m guessing in the ‘Your tickets section?

I think it would be best to work out how to get all of the registrations/events you need first before trying to work through additional customizations.

Also, will any of the helper templates point me in the right direction? I don’t see an EEH_Registrations.helper.php, but maybe a combination of the EEH_Event_View and other helpers will somehow?

The helper functions are essentially a set of files used for common tasks, the EEH_Event_view helpers pull information for the event, not registrations, and whilst you could use those for some of your data, your wanting data relating to specific registrations, which you wont get from some of the helper files.

For example, you mentioned start date, class time and day of the week above but those aren’t actually in relation to the event anymore, because an event may have multiple datetimes, so you can use something like this:

$datetime = EEH_Event_View::get_next_upcoming_date_obj( $EVT_ID );

To just pull the next datetime from the event, because that may not be the datetime the registration was made on… make sense?


lhammond

November 22, 2018 at 3:28 pm

Thanks for that code snippet! I have a custom plugin and a custom shortcode, and I have retrieved my array of ATT_IDs and then used the snippet you provided, but the call on the EEM_Registration is coming back with an empty result. Here is the code:

$attids = $wpdb->get_col($wpdb->prepare("SELECT distinct attendee_id as ATT_ID FROM ". EVENTS_MEMBER_REL_TABLE . " WHERE user_id = '%d'",  $userid), 0);
// now get registrations for those ATT_IDs
$where = array('ATT_ID' => array('IN', $attids),);
$registrations = EEM_Registration::instance()->get_all(array($where));	

That comes back with no results. However, if I just define the array manually like this:

$attids = array(15490, 15614, 16229);

Then I get results. I don’t understand why the array returned by get_col is different than the hard-coded non-indexed one, they look identical when I output them with print_r(). I tried looping over the results and reformatting them as a comma-delimited string and using that to build the array, but no luck. What am I doing wrong? I’m sure it’s something really obvious…


Tony

  • Support Staff

November 22, 2018 at 3:55 pm

Do echo $wpdb->last_query; after you have tried to pull the registrations, what does it show?


lhammond

November 22, 2018 at 6:59 pm

I figured it out! It was weird, because first I found that I needed to wrap it in another array() like this:

$where = array('ATT_ID' => array('IN', array($attids)),);

but then after reloading the page a few times, the registrations stopped showing up again, so I removed the array wrapper, and now it works fine without it.

I also figured out how to display the other fields, except I do still some questions:
1) how can I get the legend on my page that is on the my_events templates. I tried copying the code over but it takes parameters I don’t use and when I set them to NULL it doesn’t return the legend. This is what I have now – can you help me correct it so I understand what is actually needed?

        <?php EEH_Template::locate_template(
            'status-legend-espresso_my_events.template.php',
            array('template_slug' => 'simple_list_table'),
            true,
            false
        ); ?>
	    </div>

    <?php do_action('AHEE__loop-espresso_my_events__after', '', array(), 'simple_list_table', $userid); ?>

and
2. How can I display the current registration status as a pretty readable word in my list? The colors are nice, but I also want to show the text “approved” or “pending payment” etc. I was looking at the various models but couldn’t figure out how to retrieve more than the status ID. I assume there is a way to get it out of the Status model object, but I tried the localized_status() function and couldn’t figure out what to send in as the status_code to go with the status ID.


Tony

  • Support Staff

November 23, 2018 at 2:27 am

1) how can I get the legend on my page that is on the my_events templates.

I’m sorry, but I don’t follow. What are you trying to do?

The legend should display regardless, you should need to copy the additional code over (unless you previously removed it?)

Can you add a screenshot of what you see, and what you are trying to acheieve?

https://eventespresso.com/wiki/troubleshooting-checklist/#screenshots

I tried copying the code over but it takes parameters I don’t use and when I set them to NULL it doesn’t return the legend. This is what I have now – can you help me correct it so I understand what is actually needed?

Why are you overriding $template_slug with a hardcoded value? Your template should have access to that variable as EE will create it when loading the templates.

Where is $userid from? I’d advise against altering the do_action calls unless necessary which from the above I can’t see if its needed, although I’m guessing not.

2. How can I display the current registration status as a pretty readable word in my list?

I’d use:

echo EEH_Template::pretty_status($registration->status_ID(), false, 'sentence');

for pretty_status the first param is the status, second is if its plural and used for translation, last is the schema to apply:

‘upper’ = uppercase
‘lower’ = lowercase
‘sentence’ = first letter of each word upcase, eg. ‘Pending Payment’.


lhammond

November 23, 2018 at 4:38 am

Thanks, that’s just what I needed for the registration status!

I ended up just copying the relevant HTML of the legend because I only wanted to display part of it anyway.

Another question: is

$ticket->price()

the actual amount they paid, including any discounts?


Tony

  • Support Staff

November 23, 2018 at 7:44 am

I ended up just copying the relevant HTML of the legend because I only wanted to display part of it anyway.

If you let me know what you are trying to do I can let you know how to do it the ‘correct’ way (if there is one).

the actual amount they paid, including any discounts?

No, it’s the price from the ticket object.

Do you want the total from the transaction (total amount paid across all registrations?) If so thats $transactions->total();

Or the total a\mount paid per registration? $registration->paid(); or $registration->pretty_paid();

Viewing 8 reply threads

The support post ‘display registrations for multiple attendees in ESPRESSO_MY_EVENTS shortcode’ 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.

Event Espresso