Skip to content

Commit 4ae9a9b

Browse files
committed
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.
1 parent 8eef25a commit 4ae9a9b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

gp-unique-id/gpuid-multiple-ids.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ function get_count( $entry ) {
122122
if ( isset( $count['choices'] ) ) {
123123
$value = call_user_func( 'array_shift', explode( '|', rgar( $entry, $count['field_id'] ) ) );
124124
$count = rgar( $count['choices'], $value );
125+
} elseif ( ! empty( $count['field_ids'] ) && is_array( $count['field_ids'] ) ) {
126+
$counts = array_map( fn ( string|int|float $id ): string|int => rgar( $entry, $id ), $count['field_ids'] );
127+
$count = array_reduce( $counts, fn ( int $carry, string|int $count ): int => $carry + absint( $count ), 0 );
125128
} else {
126129
$count = rgar( $entry, $count['field_id'] );
127130
}

0 commit comments

Comments
 (0)