Skip to content

Commit 1e5310a

Browse files
authored
gpi-set-inventory-limit-by-day-of-the-week.php: Added new snippet.
1 parent a4fe7a3 commit 1e5310a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Inventory // Inventory Limit by Day of the Week
4+
* https://gravitywiz.com/documentation/gravity-forms-inventory/
5+
*
6+
* Set different inventory amounts depending on the day of the week selected in a scoped Date field. This snippet is
7+
* specifically configured to increase the inventory limit for weekend days.
8+
*/
9+
// Update "123" to your form ID and "4" to your Inventory-enabled field ID.
10+
add_filter( 'gpi_inventory_limit_advanced_123_4', function( $inventory_limit, $field ) {
11+
12+
// Update "5" to the value of the scoped field whose value should impact the inventory limit.
13+
$value = rgpost( 'input_5' );
14+
if ( empty( $value ) ) {
15+
return $inventory_limit;
16+
}
17+
18+
// Update "m/d/Y" to your date format.
19+
$date = DateTime::createFromFormat( 'm/d/Y', $value );
20+
21+
$day_of_week = (int) $date->format( 'w' );
22+
$is_weekend = $day_of_week === 0 || $day_of_week === 6;
23+
24+
if ( $is_weekend ) {
25+
$inventory_limit = 10;
26+
}
27+
28+
return $inventory_limit;
29+
}, 10, 2 );

0 commit comments

Comments
 (0)