This article shows how to limit the number of form submissions with ez Form Calculator.
Let’s say you have a limited number of tickets for a festival and you would like to limit the form orders to 100 tickets. Put the following code into your (child-)theme’s functions.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function ezfc_limit_form_submissions($output, $form) { // change this id to the desired form id $form_id_limit = 1; // define your limit here $limit = 1; // text if the limit has been reached $limit_text = __("Unfortunately, all tickets are sold."); // only check for the desired form if ($form_id_limit != $form->id) return $output; $ezfc = Ezfc_backend::instance(); $submissions_count = $ezfc->form_get_submissions_count($form->id); // limit reached if ($submissions_count >= $limit) { return $limit_text; } return $output; } add_filter("ezfc_form_output", "ezfc_limit_form_submissions", 10, 4); |
The variable $limit defines the maximum number of form submissions where $limit_text defines the text that will show when the form submissions number was reached. Change $form_id_limit to your desired form ID.