slaFFik
8/29/2017 - 9:00 AM

WPForms: Submit the form only once for logged in users.

WPForms: Submit the form only once for logged in users.

<?php

add_action( 'wp', function () {
	if ( ! is_user_logged_in() ) {
		return;
	}

	$entries = wpforms()->entry->get_entries(
		array(
			'form_id' => 74, // CHANGE THIS FORM ID
			'user_id' => get_current_user_id(),
		),
		true // count values only, we don't need actual data
	);

	// We allow to fill the form only once.
	if ( $entries >= 1 ) {
		add_action( 'wpforms_frontend_output_before', function () {
			echo '<p>You have already submitted this form.</p>';
		} );
		add_action( 'wpforms_frontend_load', '__return_false' );
	}
} );