Skip to content

Instantly share code, notes, and snippets.

@audrasjb
Last active December 20, 2024 10:19
Show Gist options
  • Save audrasjb/073ed605e4b47c131c859c6befca80b0 to your computer and use it in GitHub Desktop.
Save audrasjb/073ed605e4b47c131c859c6befca80b0 to your computer and use it in GitHub Desktop.
Gravity Forms: Retrieves how much available entries are available for a given form
<?php
/**
* Retrieves how much available entries are available for a given form.
*
* @param int|false $form_id The ID of the form.
*/
function jba_display_available_seats( $form_id = false ) {
if ( ! $form_id ) { return; }
$form = GFAPI::get_form( $form_id );
if ( rgar( $form, 'limitEntriesCount' ) ) {
$count = GFAPI::count_entries( 2 );
$limit = rgar( $form, 'limitEntriesCount' );
return = sprintf(
__( 'Available seats: %1$s on %2$s', 'textdomain' ),
$limit - $count,
$limit
);
}
}
?>
<!-- Example -->
<p><?php echo jba_display_available_seats( 2 ); ?></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment