Set Inventory Limit by Custom Field

This filter sets the inventory of an Advanced resource dynamically based on the inventory custom field of the post/page on which the form is embedded.

Code

Filename: gpi-set-inventory-limit-by-custom-field.php

<?php
/**
 * Gravity Perks // Inventory // Set Inventory Limit by Custom Field
 * https://gravitywiz.com/documentation/gravity-forms-inventory/
 *
 * This filter sets the inventory of an Advanced resource dynamically based on the
 * inventory custom field of the post/page on which the form is embedded.
 */
add_filter( 'gpi_inventory_limit_advanced', function() {
	// Update 'inventory' to the custom field meta key.
	return get_post_meta( get_queried_object_id(), 'inventory', 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.