diff --git a/gp-inventory/gpi-populate-days.php b/gp-inventory/gpi-populate-days.php new file mode 100644 index 000000000..d98fb0eda --- /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; +}