Events Made Easy Forums How do I … custom fields with price limit how many..

Tagged: 

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #60829
    Anonymous
    Inactive

    I have added custom fields to an event that has an impact on the price. I also want to add another custom field that does the same, however I need this to be limit to only 3 people being able to add this product… is this possible with custom fields like this?

    #60830
    Franky
    Keymaster

    It is not directly possible no. That would require going through all previous bookings, getting the answers and taking the field of interest. Using EME hooks it can be achieved, but it requires coding. A starting point can be found at https://www.e-dynamics.be/wordpress/category/documentation/12-hooks-and-filters/ , the filter eme_eval_booking_form_filter is the filter to be used (but needs extra coding then).

    Edit: maybe in your case, it would be better to work with a multi-price setup then, where you limit the number of “seats” for the second price to 3.

    #60833
    Anonymous
    Inactive

    So I have created a few prices:
    90||50||60||80

    And in the price categories:
    Workshop
    Food
    DormRoom
    PrivateSharedRoom

    How can I limit the number of PrivateSharedRoom? So that only 3 can be booked all together… ? If one bookes this, it should be 2 left… and when all 3 is gone it should not be possible for anyone else to choose this option again..

    Or is this best done using CustomFields somehow? maybe hiding if it reaches 3 booking payments or something?

    #60834
    Franky
    Keymaster

    Set the number of max seats to book per price category too, eg:

    200||100||90||3

    Use 0 for no limit if wanted.

    #60835
    Anonymous
    Inactive

    Hi Franky,

    I have now also added in
    Max number of seats to book: 19||19||13||6
    Waitinglist seats: 0
    Min number of seats to book: 1

    A few issues with this solution:

    1.
    I have also first option set to required using: #REQ_SEATS{1}. The other are #_SEATS{2}, #_SEATS{3} and #_SEATS{4}.

    – It seems that the REQ does not work in this case… as it just ignores it, because it has 0 as a value.. when I want them to be forced to choose 1 here..

    2.
    I did a test where I choose the last option that has 6 seats. And what id did was subtract a seat for option 1 that was set to required. So it shows 18 instead of 19. But the option I actually choose is still 6 seats.. expected it to show 5.

    Did I forget something here?

    #60836
    Franky
    Keymaster

    Sorry, the seats to book as a max should go in “Seats” (which is in fact the available seats per price category for your event), I was wrong there. So put in your “Seats” setting “19||19||13||6”

    The “max seats to book” indicates the max seats someone can book in one go, idem for the “min seats to book”. If you put “1” there, it will check if at leats one seat is taken from the total. If you want the minumum for the Workshop to be 1, I guess you can use this: “1||0||0||0”. The “max seats to book” can be left at 0 (unless you want to limit the max seats someone can book in 1 go for the “Workshop” or another price category).

    #60839
    Anonymous
    Inactive

    Ah yes that fixes things 🙂 Thanks.

    The two last options I would like to restrict them only to choose one or the other..
    Is it possible to do in the
    Max number of seats to book: 1||1||1||0 or 1||1||0||1 some how ?

    #60840
    Anonymous
    Inactive

    Also the price can be printed in the email as #_TOTALPRICE{xx} where xx is the number of the multi options. How can I also print the Price Categories descriptions?

    #60843
    Franky
    Keymaster

    For the price description: you can also use event placeholders, so see https://www.e-dynamics.be/wordpress/event-formatting/ (search for #_PRICEDESCRIPTION)
    Concerning your question about logic (1 or the other): that you need to create yourself using the EME filter eme_eval_booking_form_post_filter (see the doc https://www.e-dynamics.be/wordpress/hooks-and-filters/ ) and use the content of $_POST to evaluate what you want.

    #60844
    Anonymous
    Inactive

    Thanks Franky 🙂

    This is the code you mean, and how do I reach the individual price categories with the function?
    $_POST[‘bookings’][$key][‘bookedSeats’]{1}
    $_POST[‘bookings’][$key][‘bookedSeats’]{2}
    … ?

    add_filter('eme_eval_multibooking_form_post_filter','do_my_stuff');
    function do_my_stuff($events) {
        // it is recommended to add a hidden field in your form, and we check on that
        if (!isset($_POST['my_hidden_field'])) return;
    
        // as an example, let's just count the number of seats booked in total, to be sure
        $total_booked=0;
        foreach ($_POST['bookings'] as $key=>$val) {
            // format posted: $_POST['bookings'][$event_id]['bookedSeats']
            $total_booked+=$_POST['bookings'][$key]['bookedSeats'];
        }
    
        // do something for all events being registered for
        // foreach ($events as $event) {
        // .... (see the example for eme_eval_booking_post_filter)
        // }
        if ($total_booked>0) {
           // eval is success
           return array(0=>1,1=>'');
        } else {
           // bad form entry
           return array(0=>0,1=>'Not correct seats registered');
        }
    }
    #60846
    Franky
    Keymaster

    First, you need to use eme_eval_booking_form_post_filter, not eme_eval_multibooking_form_post_filter (eme_eval_multibooking_form_post_filter is for multi-booking forms, see https://www.e-dynamics.be/wordpress/category/documentation/6-shortcodes/eme_add_multibooking_form/ , but that’s not related to multiprice). In the eme_eval_booking_form_post_filter example, replace also “if ($event_id != 5) return;” with your event id, or remove the line to apply it to all events.

    The seats are normally in $_POST[‘bookings’][$event_id][‘bookedSeats’] (replace $event_id by your event id), or for multi-price: $_POST[‘bookings’][$event_id][‘bookedSeats1’], $_POST[‘bookings’][$event_id][‘bookedSeats2’], etc …

    #60849
    Anonymous
    Inactive

    Thanks Frank, this is the code and it works like a charm. 🙂

    add_filter('eme_eval_booking_form_post_filter','check_accommodation_option');
    function check_accommodation_option($event) {
        $event_id=$event['event_id'];
        $check_option_ok=0;
    
        // only do a specific event
        if ($event_id != 5) return;
    
        // only allow one booking of type Acommodation
        if($_POST['bookings'][$event_id]['bookedSeats3']==1 && $_POST['bookings'][$event_id]['bookedSeats4']==1  ){
          $check_option_ok=1;
        }
    
        if (!$check_option_ok) {
           // eval is success
           return array(0=>1,1=>'');
        } else {
           // bad form entry
           return array(0=>0,1=>'Please check only one Accommodation option');
        }
    }
    #60852
    Franky
    Keymaster

    Well, it seems ok but it will (in your code example) only work for event with id 5 (so don’t forget that).
    Also, to avoid issues if you can chose “more than one” of one Accomodation, I’d do this:

        if(intval($_POST['bookings'][$event_id]['bookedSeats3']>0) && intval($_POST['bookings'][$event_id]['bookedSeats4']>0) ) {
          $check_option_ok=1;
        }

    Or, to simplify some more (since a regular return is also accepted as ok):

    add_filter('eme_eval_booking_form_post_filter','check_accommodation_option');
    function check_accommodation_option($event) {
        $event_id=$event['event_id'];
    
        // only do a specific event
        if ($event_id != 5) return;
    
        // only allow one booking of type Acommodation
        if(intval($_POST['bookings'][$event_id]['bookedSeats3']>0) && intval($_POST['bookings'][$event_id]['bookedSeats4']>0)  ){
           return array(0=>0,1=>'Please check only one Accommodation option');
        }
    }
    #60854
    Anonymous
    Inactive

    Thanks for the added info Franky. I had the event id 5 so all good 🙂
    So appreciate your help!

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top