Disable Inventory for a Form After a Specific Date

Code

Filename: gpi-disable-inventory-after-specific-date.php

<?php
/**
 * Gravity Perks // Inventory // Disable Inventory for a Form After a Specific Date
 * https://gravitywiz.com/documentation/gravity-forms-inventory/
 */
add_filter( 'gform_form_post_get_meta', function( $form ) {

	// Update to a list of form IDs to target. Leave empty to target all forms.
	$form_ids = array();

	// Update to the date after which inventory should be disabled for the target form(s).
	$target_date = '2023-05-31';

	// Don't run on any Gravity Forms administrative page.
	if ( GFForms::get_page() ) {
		return $form;
	}

	$is_target_form = empty( $form_ids ) || in_array( $form['id'], $form_ids );
	if ( $is_target_form && gmdate( 'Y-m-d' ) > $target_date ) {
		foreach ( $form['fields'] as &$field ) {
			unset( $field->gpiInventory );
		}
	}

	return $form;
} );

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.