When your website means business.

Forms | Type: PHPShow remaining entries on Gravity Forms registration form

Displays number of entries remaining for a particular form in a shortcode entered in a wysiwyg field:

SHORTCODE: [gravityforms action=”entries_left” id=”your_form_id”]

OR show in PHP conditional:

$form_id = get_field('form_id'); //this is an ACF field
$form = RGFormsModel::get_form_meta($form_id);
$entry_count = RGFormsModel::get_lead_count($form['id'], '');
$entries_left = $form["limitEntriesCount"] - $entry_count;
if (($form) && ($today >= $regdate->format('Ymd'))) {
    if ($entries_left == "1") {
       echo '<p class="spots-left">There is <b>'.$entries_left.'</b> spot left.</p>';
    } else {
       echo '<p class="spots-left">There are <b>'.$entries_left.'</b> spots left.</p>';
    }
}
IN THEME FUNCTIONS FILE (makes both of the above work):
add_filter( 'gform_shortcode_entries_left', 'gwiz_entries_left_shortcode', 10, 2 );
function gwiz_entries_left_shortcode( $output, $atts ) {
    
    extract( shortcode_atts( array(
        'id' => false,
        'format' => false // should be 'comma', 'decimal'
    ), $atts ) );
    if( ! $id )
        return '';
    
    $form = RGFormsModel::get_form_meta( $id );
    if( ! rgar( $form, 'limitEntries' ) || ! rgar( $form, 'limitEntriesCount' ) )
        return '';
        
    $entry_count = RGFormsModel::get_lead_count( $form['id'], '', null, null, null, null, 'active' );
    $entries_left = rgar( $form, 'limitEntriesCount' ) - $entry_count;
    $output = $entries_left;
    
    if( $format ) {
        $format = $format == 'decimal' ? '.' : ',';
        $output = number_format( $entries_left, 0, false, $format );
    }
    
    return $entries_left > 0 ? $output : 0;
}

Reference Links