Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tahmid-ul/4ce5e343fd0a71ec565cbe967e7d04f5 to your computer and use it in GitHub Desktop.
Save tahmid-ul/4ce5e343fd0a71ec565cbe967e7d04f5 to your computer and use it in GitHub Desktop.
Calculate the remaining entries when the max submission limit is set and the value can be displayed in front end.
/* Snippet: A smart shortcodes will be generated that can be added to any field on the form and it will be displayed in front-end */
add_filter('fluentform_editor_shortcodes', function ($smartCodes) {
$smartCodes[0]['shortcodes']['{remaining_entries}'] = 'Remaining Entries';
return $smartCodes;
});
add_filter('fluentform_editor_shortcode_callback_remaining_entries', function ($value, $form) {
$max_entries = $form->settings['restrictions']['limitNumberOfEntries']['numberOfEntries'];
$current_entries = wpFluent()->table('fluentform_submissions')
->where('form_id', $form->id)
->get();
$available_entries = $max_entries - count($current_entries);
return $available_entries;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment