From 107137bf524904af6b5c1507f51e314644e49b9f Mon Sep 17 00:00:00 2001 From: matty0501 <17788098+matty0501@users.noreply.github.com> Date: Fri, 29 Aug 2025 14:42:40 +0100 Subject: [PATCH 1/4] `gpi-populate-days.php`: Added new snippet. --- gp-inventory/gpi-populate-days.php | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 gp-inventory/gpi-populate-days.php diff --git a/gp-inventory/gpi-populate-days.php b/gp-inventory/gpi-populate-days.php new file mode 100644 index 000000000..65232028d --- /dev/null +++ b/gp-inventory/gpi-populate-days.php @@ -0,0 +1,84 @@ +id == $field_id && $field->type == 'radio' ) { + + $choices = array(); + $today = new DateTime(); + $start_day = new DateTime( 'this ' . $day ); + + // If it's past the cutoff, also skip this week's day + if ( ( $today->format('N') == $cutoff_day && (int)$today->format('H') >= $cutoff_time ) || $today->format('N') > $cutoff_day && $today->format('N') <= $start_day->format('N') ) { + $start_day->modify('+1 week'); + } + + // Generate next n days + for ( $i = 0; $i < $number_of_days; $i++ ) { + $label = $start_day->format( $format ); + $choices[] = array( + 'text' => $label, + 'value' => $label, + 'inventory_limit' => $inventory, + ); + $start_day->modify('+1 week'); + } + + $field->choices = $choices; + } + } + + return $form; +} From 2394f5c174c8d6b27338090bc3092e8c30dbcdc1 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Fri, 29 Aug 2025 19:40:17 +0530 Subject: [PATCH 2/4] `gpi-populate-days.php`: Added new snippet. --- gp-inventory/gpi-populate-days.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gp-inventory/gpi-populate-days.php b/gp-inventory/gpi-populate-days.php index 65232028d..060d1fc39 100644 --- a/gp-inventory/gpi-populate-days.php +++ b/gp-inventory/gpi-populate-days.php @@ -2,7 +2,7 @@ /** * Gravity Perks // Inventory // Populate Days into Radio Field * https://gravitywiz.com/documentation/gravity-forms-inventory/ - * + * * Populate a Radio field with the next `n` days, and assign each choice to have `x` inventory. * * For example, you can populate a Radio field with the next 10 Thursdays, with each Thursday having an inventory of 25. @@ -10,9 +10,9 @@ * * Additionally, you can set a cutoff day and time for showing a day this week. For example, you can only show the current * 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. - * + * * Instructions: - * + * * 1. Install the snippet. * https://gravitywiz.com/documentation/how-do-i-install-a-snippet/ * @@ -44,7 +44,7 @@ function gw_populate_days_into_radio( $form ) { // Update `l, F j, Y` to the PHP date format you want the populated days to be shown in. // More information about formats can be found here: https://www.php.net/manual/en/datetime.format.php $format = 'l, F j, Y'; - + // That's it, stop editing! static $has_run = false; @@ -56,12 +56,12 @@ function gw_populate_days_into_radio( $form ) { foreach ( $form['fields'] as &$field ) { if ( $field->id == $field_id && $field->type == 'radio' ) { - $choices = array(); - $today = new DateTime(); + $choices = array(); + $today = new DateTime(); $start_day = new DateTime( 'this ' . $day ); // If it's past the cutoff, also skip this week's day - if ( ( $today->format('N') == $cutoff_day && (int)$today->format('H') >= $cutoff_time ) || $today->format('N') > $cutoff_day && $today->format('N') <= $start_day->format('N') ) { + if ( ( $today->format('N') == $cutoff_day && ( int )$today->format('H') >= $cutoff_time ) || $today->format('N') > $cutoff_day && $today->format('N') <= $start_day->format('N') ) { $start_day->modify('+1 week'); } @@ -69,8 +69,8 @@ function gw_populate_days_into_radio( $form ) { for ( $i = 0; $i < $number_of_days; $i++ ) { $label = $start_day->format( $format ); $choices[] = array( - 'text' => $label, - 'value' => $label, + 'text' => $label, + 'value' => $label, 'inventory_limit' => $inventory, ); $start_day->modify('+1 week'); From 1e78b4f6f3bf7dd43d1050c1cf05092d2634a79a Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Fri, 29 Aug 2025 19:43:51 +0530 Subject: [PATCH 3/4] `gpi-populate-days.php`: Added new snippet. --- gp-inventory/gpi-populate-days.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gp-inventory/gpi-populate-days.php b/gp-inventory/gpi-populate-days.php index 060d1fc39..6287eb1e8 100644 --- a/gp-inventory/gpi-populate-days.php +++ b/gp-inventory/gpi-populate-days.php @@ -61,13 +61,13 @@ function gw_populate_days_into_radio( $form ) { $start_day = new DateTime( 'this ' . $day ); // If it's past the cutoff, also skip this week's day - if ( ( $today->format('N') == $cutoff_day && ( int )$today->format('H') >= $cutoff_time ) || $today->format('N') > $cutoff_day && $today->format('N') <= $start_day->format('N') ) { - $start_day->modify('+1 week'); + if ( ( $today->format( 'N' ) == $cutoff_day && ( int )$today->format( 'H' ) >= $cutoff_time ) || $today->format( 'N' ) > $cutoff_day && $today->format( 'N' ) <= $start_day->format( 'N' ) ) { + $start_day->modify( '+1 week' ); } // Generate next n days for ( $i = 0; $i < $number_of_days; $i++ ) { - $label = $start_day->format( $format ); + $label = $start_day->format( $format ); $choices[] = array( 'text' => $label, 'value' => $label, From 5a3b52ae85bb1c0923742142ea0f368b256e2598 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Fri, 29 Aug 2025 19:47:49 +0530 Subject: [PATCH 4/4] `gpi-populate-days.php`: Added new snippet. --- gp-inventory/gpi-populate-days.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gp-inventory/gpi-populate-days.php b/gp-inventory/gpi-populate-days.php index 6287eb1e8..d98fb0eda 100644 --- a/gp-inventory/gpi-populate-days.php +++ b/gp-inventory/gpi-populate-days.php @@ -61,19 +61,19 @@ function gw_populate_days_into_radio( $form ) { $start_day = new DateTime( 'this ' . $day ); // If it's past the cutoff, also skip this week's day - if ( ( $today->format( 'N' ) == $cutoff_day && ( int )$today->format( 'H' ) >= $cutoff_time ) || $today->format( 'N' ) > $cutoff_day && $today->format( 'N' ) <= $start_day->format( 'N' ) ) { + if ( ( $today->format( 'N' ) == $cutoff_day && (int) $today->format( 'H' ) >= $cutoff_time ) || $today->format( 'N' ) > $cutoff_day && $today->format( 'N' ) <= $start_day->format( 'N' ) ) { $start_day->modify( '+1 week' ); } // Generate next n days for ( $i = 0; $i < $number_of_days; $i++ ) { $label = $start_day->format( $format ); - $choices[] = array( + $choices[] = array( 'text' => $label, 'value' => $label, 'inventory_limit' => $inventory, ); - $start_day->modify('+1 week'); + $start_day->modify( '+1 week' ); } $field->choices = $choices;