From 304edc37683adcb222c8faa9b3bda41dea55d7e5 Mon Sep 17 00:00:00 2001 From: Lee Hanbury Date: Thu, 7 Aug 2025 15:39:01 +0100 Subject: [PATCH] `gpuid-multiple-ids.php`: Added option to use multiple field IDs for count This is to extend the raffle/lottery ticket example on here: https://gravitywiz.com/gravity-forms-build-raffle-or-lottery/ While the guide supports "packages" of pre-defined counts for choice selections, it does not allow user-defined counts for multiple ticket types. This PR allows you to specify multiple field IDs that will all be counted and totalled to the final count allowing you to sell multiple ticket types with as many as a user would like to purchase. --- gp-unique-id/gpuid-multiple-ids.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gp-unique-id/gpuid-multiple-ids.php b/gp-unique-id/gpuid-multiple-ids.php index 2e36bf205..a1eaab7c1 100644 --- a/gp-unique-id/gpuid-multiple-ids.php +++ b/gp-unique-id/gpuid-multiple-ids.php @@ -122,6 +122,9 @@ function get_count( $entry ) { if ( isset( $count['choices'] ) ) { $value = call_user_func( 'array_shift', explode( '|', rgar( $entry, $count['field_id'] ) ) ); $count = rgar( $count['choices'], $value ); + } elseif ( ! empty( $count['field_ids'] ) && is_array( $count['field_ids'] ) ) { + $counts = array_map( fn ( string|int|float $id ): string|int => rgar( $entry, $id ), $count['field_ids'] ); + $count = array_reduce( $counts, fn ( int $carry, string|int $count ): int => $carry + absint( $count ), 0 ); } else { $count = rgar( $entry, $count['field_id'] ); } @@ -188,3 +191,15 @@ function reinforce_check_unqiue_query( $query, $form_id, $field_id, $unique ) { // ) // ) // ) ); + +// new GPUID_Multiple_IDs( array( +// 'form_id' => 694, +// 'target_field_id' => 36, +// 'source_field_id' => 35, +// 'count' => array( +// 'field_ids' => array( +// '11.3', +// 20, +// ), +// ), +// ) );