• Hello,
    When using the em_booking_save hook there is only one variable being passed. And that is a boolean.
    I need to use the Event_id with some conditional logic in the hook.

    How can i achieve this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The em_booking_save filter passes up to 3 variables. When you call add_filter the default is to only to pass in 1 variable (which is type boolean). Use the following:

    add_filter('em_booking_save', 'my_booking_save_filter', 10, 3);
    function my_booking_save_filter($errors, $EM_Booking, $update) {
    $event_id = $EM_Booking->event_id;
    // your conditional logic goes here
    return $errors;
    }

    The $update variable is true if this is a change to an existing booking.

    Thread Starter EmanuelHut

    (@emanuelhut)

    When using this method i get the following error when someone does a booking.

    “message”: “Uncaught Error: Too few arguments to function {closure}(), 1 passed in /wp-includes/class-wp-hook.php on line 326 and exactly 3 expected in functions.php on line 387”,

    I tried this and it worked fine (I did not get the error you show).

    The calls to apply_filter for the em_booking_save filter are located on lines 374 and 395 of events-manager/classes/em-booking.php:

               apply_filters('em_booking_save', ( count($this->errors) == 0 ), $this, $update);
    apply_filters('em_booking_save', false, $this, false);

    You can see that 3 arguments are being passed. Either the events manager code was modified or there is some other place outside of the events manager plugin that is calling apply_filters on em_booking_save without the 3 parameters on your website.

    Thread Starter EmanuelHut

    (@emanuelhut)

    Thanks for you response! You are totally right.
    Above this code i had another piece of code which came from this topic:
    https://ww.wp.xz.cn/support/topic/hook-after-registration-for-event/

    After changing that function to $status, $EM_Booking, $update and adding return $status in both functions it’s working as intended!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘em_booking_save hook’ is closed to new replies.