Posted: October 25, 2024 at 3:30 pm
My client has many events that share the same name, but occur on different dates. This is making it confusing to understand what a user has purchased at checkout. I’d like to modify the checkout process to show the date that each event occurs next to its name, but from what I can tell, there are no hooks to do so. We’re using the “Multiple Event Registration” add-on. How can we display the date? |
|
Hi there, The hooks you need for this depend on the specific location you are wanting to include the dates. Can you add an example? For example a screenshot of where/how you would like the dates to be output? https://eventespresso.com/wiki/troubleshooting-checklist/#screenshots The 3 hooks that come to mind for me are:
I have a couple of examples of using those here: https://gist.github.com/Pebblo/2b0433f851e18d6ddd6fb85eca78b440 But it really does depend on the specifics of what you are wanting to do. |
|
Thanks, I was able to make it work with the below code. This inserts the date below the event title, above the ticket name, which works, but *ideally* I think I’d like the event date to be added after the title with an Screenshot: https://imgur.com/a/jFIlF17 /** * Add dates to events cart */ add_filter("FHEE__EE_Event_Cart_Line_Item_Display_Strategy___ticket_row__name_and_desc", function (string $original_description, EE_Line_Item $line_item, bool $required): string { $event = $line_item->ticket_event(); if (! $event) { return $original_description; } $date = pofo_child_event_espresso_event_get_date_range($event->ID(), "F j, Y"); if ($date) { $original_description = "{$date}<br />{$original_description}"; } return $original_description; }, 10, 3); |
|
I checked into this and we don’t have a filter for it currently, I’ll open a discussion on adding one to allow for editing the ‘event row’.
Depends on where you are looking 😉 The first 2 hooks will change the output on the SPCO Display strategies, so the line items shown above the attendee information and payment methods. The last one in my list is specifically for the event cart output. |
|
Great, thanks, I was able to finalize the functionality like this: /** * Display event dates during the checkout process * * @param string $value * @param EE_Line_Item $line_item * @return void */ function pofo_child_event_espresso_insert_date(string $value, EE_Line_Item $line_item) { $event = $line_item->ticket_event(); if (! $event) { return $value; } $date = pofo_child_event_espresso_event_get_date_range($event->ID(), "F j, Y"); if ($date) { $value = "{$date}<br />{$value}"; } return $value; } add_filter("FHEE__EE_Event_Cart_Line_Item_Display_Strategy___ticket_row__name_and_desc", "pofo_child_event_espresso_insert_date", 10, 2); add_filter("FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name", "pofo_child_event_espresso_insert_date", 10, 2); add_filter("FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name", "pofo_child_event_espresso_insert_date", 10, 2); /** * Get the date range of an event * * @param integer $event_id */ function pofo_child_event_espresso_event_get_date_range(int $event_id = 0, string $format = "m/d/Y"): string { global $post; if ($event_id) { $post = get_post($event_id); } $start_date = new DateTime(espresso_event_date("Y/m/d", "H:i e", false, false)); $end_date = new DateTime(espresso_event_end_date("Y/m/d", "H:i e", false, false)); if ($start_date->format("Ymd") === $end_date->format("Ymd")) { return $start_date->format($format); } if ($event_id) { wp_reset_postdata(); } return "{$start_date->format($format)} – {$end_date->format($format)}"; } I think this should work for my clients purposes |
|
Awesome, thanks for sharing your solution here and I’m glad those worked for you. Any further questions just let me know. |
|
One more question, is there a way to add the dates to this section when editing a coupon code? https://imgur.com/a/O0y8fLQ |
|
Sure, there’s a filter:
|
|
The support post ‘Display event date on cart and checkout’ 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.