Set Limit Period by User Meta

Code

Filename: gpls-set-limit-period-by-user-meta.php

<?php
/**
 * Gravity Perks // Limit Submissions // Set Limit Period by User Meta
 * https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
 */
add_action( 'gpls_before_query', function( $ruletest ) {
	global $wpdb;

	// Update "123" to your form ID.
	if ( $ruletest->form_id != 123 ) {
		return;
	}

	// Update "subscription_start_date" to your user meta key.
	$subscription_start_date = get_user_meta( get_current_user_id(), 'subscription_start_date', true );
	$time_period_sql         = $wpdb->prepare( 'date_created BETWEEN %s AND DATE_ADD( CURDATE(), INTERVAL 1 DAY )', $subscription_start_date );
	$ruletest->where[]       = $time_period_sql;

} );

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.