Support

Home Forums Event Espresso Premium Retrieve custom fields in Event Table View Add-On

Retrieve custom fields in Event Table View Add-On

Posted: October 23, 2018 at 9:25 am

Viewing 7 reply threads


lhammond

October 23, 2018 at 9:25 am

I’ve figured out how to get most of the fields I want to display in my Events Table View Template Add-on modifications, except when I try to get my own custom fields (formerly event_meta fields), I am using this:

<?php get_post_meta($post->ID, 'instructor', true); ?>

but it is coming back empty, despite the fact that I can see it when I edit my event. What am I doing wrong?

Also, how can I make the Add to Cart button use AJAX like it used to in EE3 and come right back to the same page?

And finally, how can I make the Add to Cart button show a Waitlist button instead if the event is sold out, and let the users add it to the cart to save their info as a waitlist registration?


Tony

  • Support Staff

October 23, 2018 at 10:08 am

Hi there,

but it is coming back empty, despite the fact that I can see it when I edit my event. What am I doing wrong?

How did you add the ‘instructor’ field? Are you sure the meta key for the field is just ‘instructor’?

Note if you have the EE_Event object, which the table view template does within $event you can use:

$event->get_post_meta('instructor', true);

To do the same without passing the ID (the event object does it for you).

Also, how can I make the Add to Cart button use AJAX like it used to in EE3 and come right back to the same page?

Thats not something we currently have for EE4, or at least, not in the same way it did with EE3.

EE3 added the events to the cart and then allowed you to select the tickets for each event in the cart before you could check out.

EE4 uses the Ticket Selector to display the tickets for the event, the user selects the specific tickets they need and then adds them to the cart directly from there.

As you are referring to the Event Table template, I’m assuming you want to add the tickets directly from that, which you can do using this template:

https://gist.github.com/joshfeck/e8fcb3946f56490d1384bfcc449caa9b#file-espresso-events-table-template-template-php-L119

And finally, how can I make the Add to Cart button show a Waitlist button instead if the event is sold out, and let the users add it to the cart to save their info as a waitlist registration?

The waitlist button is added within the ticket selector, so if you show the ticket selector using the above, this would happen automatically for you.


lhammond

October 23, 2018 at 12:33 pm

I tried using

$event->get_post_meta('instructor', true); 

and that also came back empty. I am using the default template provided with the add-on, and just added some columns to the display. So I do have the $event object, yet… where is that info? Is there a way I can query for it using phpMyAdmin on the backend to make sure it’s there? But it does show on the event editing page.

Regarding the AJAX add to cart option, does the sessions till hold the cart variables the way it used to? Maybe I could use some of the old EE3 code when modifying my table.

All of our classes only have one ticket type right now (although we may branch out for certain one-day workshops), so the desired behavior is to have the Add to Cart button add one ticket of the only ticket option there is, and if they need more than one, they can edit that in the cart. And if the class is full, the button in the table would hold a spot in the waitlist. Is there a way to do that easily?

Also, do the seats get pulled out of the database at the moment they are added to the cart, even before checkout is completed? We often have a rush on registration day, and it has been an issue in the past if people lost their seat while filling out their forms.


Tony

  • Support Staff

October 23, 2018 at 1:06 pm

and that also came back empty

Ok, so that sounds like you don’t have a custom field with the key ‘instructor’.

I am using the default template provided with the add-on, and just added some columns to the display. So I do have the $event object, yet… where is that info?

You’ll see:

$event = EEH_Event_View::get_event();

$event should then be the EE_Event object.

You’ll also see:

$external_url = $post->EE_Event->external_url();

That’s the EE_Event object attached to the post being used to pull the extrnal_url.

Is there a way I can query for it using phpMyAdmin on the backend to make sure it’s there? But it does show on the event editing page.

What exactly do you see on the event editor? Can you add a screenshot?

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

Regarding the AJAX add to cart option, does the sessions till hold the cart variables the way it used to? Maybe I could use some of the old EE3 code when modifying my table.

It still holds a session, but in a completely different way.

EE4 was a complete rebuild of EE, its not simply an update to a new version, but a completely different system.

All of our classes only have one ticket type right now (although we may branch out for certain one-day workshops), so the desired behavior is to have the Add to Cart button add one ticket of the only ticket option there is, and if they need more than one, they can edit that in the cart. And if the class is full, the button in the table would hold a spot in the waitlist. Is there a way to do that easily?

You’ll need to use the ticket selector, you can hide sections of it using CSS, but there’s no single button submission with EE4 like there was with EE3.

Can you post a link to what you have now?

Also, do the seats get pulled out of the database at the moment they are added to the cart, even before checkout is completed? We often have a rush on registration day, and it has been an issue in the past if people lost their seat while filling out their forms.

EE places your ticket selections on reserve for the duration of your session (by default 1 hour), so if you have 2 tickets left and a user selects those 2 tickets but it still adding their details to the forms and the next user loads the event/ticket selector for the event, the new user will see no tickets available (sold out). If the first user doesn’t complete their registration the tickets are released and the next user to load the ticket selector can select them.


lhammond

October 24, 2018 at 8:32 pm

Ok, so that sounds like you don’t have a custom field with the key ‘instructor’.

I am certain I do (instructor, day_of_week, etc.), and they are visible in the custom fields section when I edit the event, just like this guy’s screen grab: https://drive.google.com/file/d/0B2KCao4zFjaxWU53Yi11eDVDdlU/view

I tried all of these variations with no luck:

$post->EE_Event->get_post_meta('day_of_week', true); 
$event->get_post_meta('day_of_week', true); 
get_post_meta($post->ID, 'day_of_week', true);

Clearly I’m missing something here, probably something easy and obvious! Thanks for your help.


lhammond

October 24, 2018 at 8:43 pm

Also, when I try to use the debugging framework, e.g.

d( $post );

I get a fatal error, Call to undefined function d().

I have the template in my child theme folder.


lhammond

October 24, 2018 at 8:51 pm

Oh my goodness, I knew it was something obvious. All three of the methods I tried *do* work when you remember to echo them to the screen, not just retrieve them! Oops.

I still don’t know why the debug framework is throwing an error, though. And I will look into hiding what I don’t need of the ticket selector, or perhaps customizing it to just show the Add to Cart or Waitlist buttons, as appropriate.

Thanks!


Josh

  • Support Staff

October 25, 2018 at 6:54 am

Hi Laura,

You’ll need to install a kint debugging plugin in order to use its d() function. Kint is not bundled into the production version of Event Espresso 4.

There are a few options available to download from wordpress.org:
https://wordpress.org/plugins/kint-php-debugger/
https://wordpress.org/plugins/kint-debugger/

Viewing 7 reply threads

The support post ‘Retrieve custom fields in Event Table View Add-On’ 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