Limit by Paid Entries Only

Only count entries with a Paid payment status when enforcing Limit Submissions rules so users with failed payments can submit again.

Instructions

See “Where do I put snippets?” in our documentation for installation instructions.

Code

Filename: gpls-limit-by-paid-entries-only.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
 * Gravity Perks // Limit Submissions // Limit by Paid Entries Only
 * https://gravitywiz.com/documentation/gravity-forms-limit-submissions
 *
 * Only count entries with a Paid payment status when enforcing Limit Submissions rules so users with failed payments can submit again.
 */
add_action( 'gpls_before_query', function ( $ruletest ) {

	// Replace '123' with your Form ID. Leave empty to apply to all forms.
	$form_ids = array( 123 );

	if ( ! empty( $form_ids ) && ! in_array( (int) $ruletest->form_id, array_map( 'intval', $form_ids ), true ) ) {
		return;
	}

	static $processed = array();
	$key              = spl_object_hash( $ruletest );

	if ( isset( $processed[ $key ] ) ) {
		return;
	}

	$ruletest->where[] = "( e.payment_status = 'Paid' OR e.payment_status IS NULL OR e.payment_status = '' )";

	$processed[ $key ] = true;
} );

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.