Enable Use of the Total Field with Conditional Logic

Introduction

The Total field is not made available to configure conditional logic rules, as it is evaluated differently to other fields. The following snippet does make it possible to use in conditional logic rules, but with the limitation that this is only appropriate for conditional logic that takes place after entry submission.

Usage Limitations

Conditional logic using the Total field is only for use on notifications and confirmations processed after submission. That is, features where logic is evaluated based on the saved entry.

Because the total field is always the last field to be saved you cannot use it to configure conditional logic on other fields on the form. 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.

Placement

The snippet should be placed in the functions.php file of your active theme or a custom functions plugin. You will then be able to configure less than and greater than rules based on the value of the Total field.

Snippet

add_action( 'admin_enqueue_scripts', function () {
	$pages = array( 'confirmation', 'notification_edit' );
	if ( ! class_exists( 'GFForms' ) || ! in_array( GFForms::get_page(), $pages ) ) {
		return;
	}

	$script =
		"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;' .
		'});';

	wp_add_inline_script( 'gform_form_admin', $script );
}, 11 );

Alternatives

Check out our community add-on library to search for the possible options.