bookmark_borderEnable use of the Total field with Conditional Logic

The Total field can’t be used to configure conditional logic rules, the following snippet makes that possible. The snippet should be placed in the functions.php file of your active theme. You will then be able to configure less than and greater than rules based on the value of the Total field.

Important:
Because the total field is always the last field to be saved you can’t use it when configuring conditional logic on other fields. Displaying other fields based on the total would prevent those fields being saved as the conditions would never match when the logic is evaluated during submission. Total field logic is only intended for use on notifications, confirmations and add-on feeds, features where logic is evaluated based on the saved entry.

class RW_GF_Total_Field_Logic {

	public function __construct() {
		add_action( 'init', array( $this, 'init' ) );
	}

	function init() {
		if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) {
			return;
		}

		add_filter( 'gform_field_content', array( $this, 'maybe_add_logic_event' ), 10, 2 );
		add_filter( 'gform_admin_pre_render', array( $this, 'enable_total_in_conditional_logic' ) );
	}

	function maybe_add_logic_event( $content, $field ) {
		if ( $field->type != 'total' ) {
			return $content;
		}
		$logic_event = $field->get_conditional_logic_event( 'change' );

		return ! empty( $logic_event ) ? str_replace( "gform_hidden'", "gform_hidden' value='0' {$logic_event}", $content ) : $content;

	}

	function enable_total_in_conditional_logic( $form ) {
		if ( GFCommon::is_entry_detail() ) {
			return $form;
		}

		echo "<script type='text/javascript'>" .
		     " gform.addFilter('gform_is_conditional_logic_field', function (isConditionalLogicField, field) {" .
		     "     return field.type == 'total' ? true : isConditionalLogicField;" .
		     '	});' .
		     "	gform.addFilter('gform_conditional_logic_operators', function (operators, objectType, fieldId) {" .
		     '		var targetField = GetFieldById(fieldId);' .
		     "		if (targetField && targetField['type'] == 'total') {" .
		     "			operators = {'>': 'greaterThan', '<': 'lessThan'};" .
		     '		}' .
		     '		return operators;' .
		     '	});' .
		     '</script>';

		return $form;
	}

}
new RW_GF_Total_Field_Logic();