Skip to content

Commit 322ea22

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 a77bf8e commit 322ea22

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 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
}
@@ -188,3 +191,15 @@ function reinforce_check_unqiue_query( $query, $form_id, $field_id, $unique ) {
188191
// )
189192
// )
190193
// ) );
194+
195+
// new GPUID_Multiple_IDs( array(
196+
// 'form_id' => 694,
197+
// 'target_field_id' => 36,
198+
// 'source_field_id' => 35,
199+
// 'count' => array(
200+
// 'field_ids' => array(
201+
// '11.3',
202+
// '20'
203+
// )
204+
// )
205+
// ) );

0 commit comments

Comments
 (0)