Display Entries Left Based on Entry Limit

Code

Filename: gw-display-number-of-entries-left-based-on-entry-limit.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Display Entries Left Based on Entry Limit
 *
 * https://gravitywiz.com/display-number-of-entries-left-based-on-entry-limit/
 *
 * @version  1.0
 * @author   David Smith <david@gravitywiz.com>
 * @license  GPL-2.0+
 * @link     https://gravitywiz.com/
 */

// update the "4" to the ID of your form
add_action( 'gform_pre_render_4', 'gform_display_limit' );
function gform_display_limit( $form ) {

	// put the %s wherever you want the number of entries to display in your message
	$entries_left_message = 'Only %s positions left!';

	/* You do not need to edit below this line */

	$entry_count  = RGFormsModel::get_lead_count( $form['id'], '' );
	$entries_left = $form['limitEntriesCount'] - $entry_count;

	if ( $entries_left > 0 ) {
		$form['description'] .= sprintf( '<div class="entries-left">' . $entries_left_message . '</div>', $entries_left );
	}

	return $form;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.