22/**
33 * Gravity Perks // Inventory // Populate Days into Radio Field
44 * https://gravitywiz.com/documentation/gravity-forms-inventory/
5- *
5+ *
66 * Populate a Radio field with the next `n` days, and assign each choice to have `x` inventory.
77 *
88 * For example, you can populate a Radio field with the next 10 Thursdays, with each Thursday having an inventory of 25.
99 * This is useful if you offer a service on a specific day only, and need users to select which date they want.
1010 *
1111 * Additionally, you can set a cutoff day and time for showing a day this week. For example, you can only show the current
1212 * week's Thursday if it is before 4pm on Tuesday. This is useful if you need to set a cut-off time for bookings this week.
13- *
13+ *
1414 * Instructions:
15- *
15+ *
1616 * 1. Install the snippet.
1717 * https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
1818 *
@@ -44,7 +44,7 @@ function gw_populate_days_into_radio( $form ) {
4444 // Update `l, F j, Y` to the PHP date format you want the populated days to be shown in.
4545 // More information about formats can be found here: https://www.php.net/manual/en/datetime.format.php
4646 $ format = 'l, F j, Y ' ;
47-
47+
4848 // That's it, stop editing!
4949
5050 static $ has_run = false ;
@@ -56,21 +56,21 @@ function gw_populate_days_into_radio( $form ) {
5656 foreach ( $ form ['fields ' ] as &$ field ) {
5757 if ( $ field ->id == $ field_id && $ field ->type == 'radio ' ) {
5858
59- $ choices = array ();
60- $ today = new DateTime ();
59+ $ choices = array ();
60+ $ today = new DateTime ();
6161 $ start_day = new DateTime ( 'this ' . $ day );
6262
6363 // If it's past the cutoff, also skip this week's day
64- if ( ( $ today ->format ('N ' ) == $ cutoff_day && (int )$ today ->format ('H ' ) >= $ cutoff_time ) || $ today ->format ('N ' ) > $ cutoff_day && $ today ->format ('N ' ) <= $ start_day ->format ('N ' ) ) {
64+ if ( ( $ today ->format ('N ' ) == $ cutoff_day && ( int )$ today ->format ('H ' ) >= $ cutoff_time ) || $ today ->format ('N ' ) > $ cutoff_day && $ today ->format ('N ' ) <= $ start_day ->format ('N ' ) ) {
6565 $ start_day ->modify ('+1 week ' );
6666 }
6767
6868 // Generate next n days
6969 for ( $ i = 0 ; $ i < $ number_of_days ; $ i ++ ) {
7070 $ label = $ start_day ->format ( $ format );
7171 $ choices [] = array (
72- 'text ' => $ label ,
73- 'value ' => $ label ,
72+ 'text ' => $ label ,
73+ 'value ' => $ label ,
7474 'inventory_limit ' => $ inventory ,
7575 );
7676 $ start_day ->modify ('+1 week ' );
0 commit comments