Support

Home Forums Event Espresso Premium Display event date on cart and checkout

Display event date on cart and checkout

Posted: October 25, 2024 at 3:30 pm

Viewing 7 reply threads


weblinxinc

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?


Tony

  • Support Staff

October 28, 2024 at 11:59 am

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:

FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc
FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc
FHEE__EE_Event_Cart_Line_Item_Display_Strategy___ticket_row__name_and_desc

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.


weblinxinc

October 28, 2024 at 1:28 pm

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 –. None of the other suggested hooks seemed to do anything, only the last one.

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);


Tony

  • Support Staff

October 28, 2024 at 5:12 pm

I think I’d like the event date to be added after the title with an &ndash;

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’.

None of the other suggested hooks seemed to do anything, only the last one.

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.


weblinxinc

October 29, 2024 at 9:20 am

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


Tony

  • Support Staff

October 29, 2024 at 1:25 pm

Awesome, thanks for sharing your solution here and I’m glad those worked for you.

Any further questions just let me know.


weblinxinc

October 30, 2024 at 7:45 am

One more question, is there a way to add the dates to this section when editing a coupon code? https://imgur.com/a/O0y8fLQ


Tony

  • Support Staff

October 30, 2024 at 2:41 pm

Sure, there’s a filter:

apply_filters(
    'FHEE__EE_Promotion_Scope___get_applies_to_items_to_select__obj_name',
    $this->name($obj),
    $obj
)

$obj at that point will be an EE_Event.

Viewing 7 reply threads

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.

Event Espresso