The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Reduce the number of available tickets by X

Labels

This Discussion is public

Notifications

This is a variation to the existing KB article Decrease an available count in another form.

I wanted to decrease a number in another form by using a field in my current form which can be variable and therefore not just by a fixed number as per the existing article.

Here's the set-up:

Form 1: Event Management Form - Admin Only

This form is used for adding new events and contains the following fields (although you can add any fields you like):

  • Event Name
  • Event Date
  • Number of places available
  • Event Description

Form 2: Event Booking Form

This form is your event booking form and uses a Dynamic Dropdown field to look at Form 1 > Event Date and display the dates available.

It also uses a 2nd Dynamic List field to display the number of places still available and a hidden field to capture this number which can then be used elsewhere in the form to control conditional logic for your form elements if the number of places gets below X.

To make the number of seats decrease by a variable amount (instead of a fixed amount like the KB article shows) use this function:

add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
  if($form_id == 9){ //change 9 to the ID of your reservations form
    global $wpdb;
    $reward_ids = $_POST['item_meta'][95]; //change 95 to the ID of your Dynamic dropdown field in your reservations form
$booking_num = $_POST['item_meta'][96]; //change 96 to the ID of your booking places field in your reservations form
    $seat_count_field = 91; //change 91 to the ID of the available seats field in the event form
    foreach ( (array) $reward_ids as $reward_id ) {
        $available = FrmEntryMeta::get_entry_meta_by_field( $reward_id, $seat_count_field, $booking_num, true );
        $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => ( (int) $available-$booking_num ) ), array( 'item_id' => $reward_id, 'field_id' => $seat_count_field ) );

    }
  }
}

 

Field 95 is the ID of the Dynamic Dropdown field in your booking form.

Field 96 is the ID of the number of places that are being booked.

Field 91 is the ID of the number of places in Form 1

9 is the ID of Form 2

 

Enjoy 🙂

 

 

Hi Ronoi,

That works great for a direct Dynamic Dropdown. Thanks!

How can we make it work for Lookup fields?

My event has several time slots on the same date, so to register a place, the selection is like:

Event > Date > Time

Many thanks!

Al

Discussion closed.