Posted: March 15, 2018 at 8:39 am
We sell courses (e.g. Yoga, Pilates) with multiple datetimes, mostly 8 times, per event. I understand that the upcoming status is if the current date is before the event datetime. This makes sense for long events. With multiple datetimes an event last for at least 8 weeks. So the status upcoming is misleading for some customers because the course has already begun after the first datetime. |
|
No I’m afraid it’s not possible to define the active status that way. |
|
Okay!? Is it possible than just change somehow the sign „upcoming“ on the event page, table list template and calendar on the frontend to „in progress“ between the first and last datetime? The official status doesn’t have to be change. It’s just have to be clear everywhere for the customers that the course has startet and is in progress. |
|
I don’t believe the table list template or calendar shows the Datetime status. For the event page, you can set “Display Status Banner?” to “No” on the Event Espresso > Events > Templates settings page and the banner will no longer display. |
|
I would like to communicate somehow that the course has started and is in progress. On the eventpage like described or add an additional banner in the text that show automatically if the course is in progress. On the table list and calendar change the text from „register“ to „in progress“. |
|
Hi there, This isn’t a supported feature and would require custom PHP programming to add these. I’m afraid we do not have any code examples that are remotely related to defining active statuses. |
|
Hey Josh, I would like to add an automated text on the event page via php for the the following cases: With a bit of styling it would look like banner and would show in a glance what status the course is in. I’ve found the template tags on https://eventespresso.com/wiki/ee4-themes-templates/. I guess I need the espresso_event_date() for the start date and espresso_event_status() for the status. I am just started with php and still figuring out how to achieve this. Maybe you could give me a direction or maybe an example how a similar case is what exist already. |
|
Hi there, The espresso_event_date() tag will only return the first Datetime of the event, and espresso_event_status() will return these statuses: One thing to keep in mind is there are two classes that handle the active status logic, one for events and one for datetimes. Here are links to the source PHP for those: |
|
Hey Josh, My current action looks like this: add_action('AHEE_event_details_after_the_content', 'my_custom_event_status_banner'); function my_custom_event_status_banner() { $today = time(); $event_start = strtotime(espresso_event_date()); // get the end date of current event $event_end = strtotime(espresso_event_end_date()); // check if the current event status is not canceled $event_status_is_not_canceled = $post->EE_Event->is_cancelled() == false; // check if the current event status is canceled $event_status_is_canceled = !$post->EE_Event->is_cancelled() == false ; if ( $event_status_is_not_canceled && $today < $event_start) { echo "open for sale"; } elseif ($event_status_is_not_canceled && $today > $event_start && $today < $event_end) { echo "course pending"; } elseif ($event_status_is_not_canceled && $today > $event_end) { echo "course ended"; } elseif ($event_status_is_canceled) { echo "course is canceled"; } } How can I check if the event is canceled or not in the if statement? I understand that it is the is_cancelled function but I can’t figure out how to use it. The second part is that espresso_event_date() echoing the result if want to use it as a variable. I have to return the value of that and than edit it by the strtotime function to be able to compare it in the if statement. I would appreciate if you give me maybe an existing example how to do those two things. |
|
Okay, I figured out how to check the status $event_status_is_not_canceled = !$public_event_stati->EE_Event->is_cancelled(); and adding $public_event_stati to the function. |
|
I can’t figuring out how to pull the information from /** * Set event start date * set the start date for an event * * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 * @throws ReflectionException * @throws InvalidArgumentException * @throws InvalidInterfaceException * @throws InvalidDataTypeException * @throws EE_Error */ public function set_start_date($date) { $this->_set_date_for($date, 'DTT_EVT_start'); } |
|
Sorry I mean: /** * get event start date. Provide either the date format, or NULL to re-use the * last-used format, or '' to use the default date format * * @param string $dt_frmt string representation of date format defaults to 'F j, Y' * @return mixed string on success, FALSE on fail * @throws ReflectionException * @throws InvalidArgumentException * @throws InvalidInterfaceException * @throws InvalidDataTypeException * @throws EE_Error */ public function start_date($dt_frmt = '') { return $this->_show_datetime('D', 'start', $dt_frmt); } |
|
What do you mean by pulling info?
Would assign to the start to dat to the |
|
Hey Tony, I appreciate the example from you a lot but I also understand that the purpose of the support is not to write everything for me. It would help me a lot, if you give the info how to fill the variables, e.g. in this case the info $event_status_is_not_canceled and $start_date. I would love to learn to write myself and use this as a project to learn it. For the variable that doesn’t look right: I am always searching the forum for cases that I could use. In this case I found not that code but similar in different post and tried it to apply it here. By trial and error this worked and showed my the test echo on the page. I know that I’ve posted a lot of topics so far. So I thank you guys for your work and hope that your answers don’t only help me but others how also are beginners. |
|
Hi Thomas, One way to learn is from looking at similar code from within the project. One similar example is the espresso_event_reg_button() template tag which does something similar: https://github.com/eventespresso/event-espresso-core/blob/master/public/template_tags.php#L251 |
|
Hey Josh, thank you for the link. I found a lot of information by searching examples and infos here but it is a lot to process. I am trying to make sense of the structure of EE. I understand that a method is calling another method to have a flexibel system. But it is hard to follow where to find the other class and method. The guide from the other post was very helpful but I am stuck how to call method. I found also the model https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md Let me know if I am starting to annoy you with my question. |
|
So I went through the classes and I guess I kinda get it. Here is my code for the custom banner and is working. // Add custom banner after the content add_action('AHEE_event_details_after_the_content', 'my_test_function'); function my_test_function() { $today = time(); $first_date_object = EEH_Event_View::get_primary_date_obj( ); $first_date_timestamp = $first_date_object instanceof EE_Datetime ? $first_date_object->get_raw( 'DTT_EVT_start' ) : ''; $last_date_object = EEH_Event_View::get_last_date_obj( ); $last_date_timestamp = $last_date_object instanceof EE_Datetime ? $last_date_object->get_raw( 'DTT_EVT_end' ) : ''; $get_event = EEH_Event_View::get_event(); $event_is_canceled = $get_event instanceof EE_Event ? $get_event->is_cancelled() : ''; $event_is_soldout = $get_event instanceof EE_Event ? $get_event->is_sold_out() : ''; if ($event_is_canceled==true) { echo "<span class=\"banner banner_canceled\">canceled</span>"; } elseif ($event_is_soldout==true){ echo "<span class=\"banner banner_sold_out\">event is sold out</span>"; } elseif ($today < $first_date_timestamp){ echo "<span class=\"banner banner_open\">open for registration</span>"; } elseif ($first_date_timestamp < $today && $today < $last_date_timestamp){ echo "<span class=\"banner banner_pending\">pending</span>"; } elseif ($last_date_timestamp < $today){ echo "<span class=\"banner banner_expired\">expired</span>"; } } And the CSS to that belongs to that banner. add_action( 'wp_head', 'css_for_custom_plugin_functions_ee' ); function css_for_custom_plugin_functions_ee() { ?> <style type="text/css"> .banner{ display: inline-block; position: relative; float: right; z-index: 1; padding: 0.5em 1.5em 0.5em; margin: 0 0 0 1em; border-bottom: 1px solid rgba(0,0,0,0.1); font-weight: bold; color: #fff !important; text-decoration: none; text-align: center; text-shadow: 0 -1px 0 rgba(0,0,0,0.25); font-size: 1.5em; line-height: 1; border-radius: 0; box-shadow: none; } .banner_canceled{ background-color: red; } .banner_sold_out{ background-color: orange; } .banner_open{ background-color: #00B1CA; } .banner_pending{ background-color: green; } .banner_expired{ background-color: grey; } </style> <?php } Even though the code works, I am not sure exactly what is stored in the variables. Becomes the variable an object of the class? If it’s possible it would be great to get some infos to my questions from my previous post to understand the ee system better. |
|
You can get a better insight of what’s stored in each variable by installing the Kint Debugger plugin, then as you’re coding, and wondering about a variable, you add a line of temporary debug code like this: Then view the browser/refresh and Kint will display all kinds of information about the variable. Side note: If you’re using the non-release-tag version of Event Espresso from Github then Kint is already included from within the plugin. |
|
Thank you Josh, I will try it. I would like to add an additional condition. We have a custom message template for the group “registration approved” that we send out to confirm the start of the course and new registration will receive the same info. Which method would you recommend to check if this message group is set to “global” or check if this uses the custom template name “course confirmed”? |
|
It’s not my place to recommend, but I can point you to the EE_Messages_Generator class that has similar logic: |
|
The support post ‘Active status for multiple 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.