Last active
May 17, 2021 07:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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