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 );
} );
Can you expand on how this works please, I’ve added the snippet but nothing seems to be happening. Do you need to select Inventory “Advanced” and add a scope ? or do you leave all unset and this just works – sorry I’m confused.
Hi Kenny,
The way it works is that you’ll need to update ‘inventory’ as commented in the code to match your meta key of the custom field with the inventory limit value. Then, you’ll need to set your Inventory type to Advanced and set up a Resource. A scope is not needed here. This snippet sets the inventory of an Advanced resource dynamically based on the value of the custom field.
I hope this helps. However, if it’s still not working for you, send us a message via our support form so we can look into this on your end.
Best,