Skip to content

Commit 3602b36

Browse files
authored
gw-include-option-label-and-value-in-order-summary.php: Added new snippet.
1 parent 60fb8a0 commit 3602b36

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Gravity Wiz // Gravity Forms // Include Option Label & Value in Order Summary
4+
* https://gravitywiz.com/
5+
*
6+
* By default, Gravity Forms only includes select options' labels or values depending on the context. Use this snippet
7+
* to include both the label and value wherever the order summary is displayed (e.g. Entry Detail, {all_fields}, etc).
8+
*/
9+
add_filter( 'gform_product_info', function( $product_info, $form ) {
10+
foreach( $product_info['products'] as &$product ) {
11+
foreach( $product['options'] as &$option ) {
12+
$field = GFAPI::get_field( $form, $option['id'] );
13+
foreach ( $field->choices as $choice ) {
14+
if ( $choice['text'] !== $choice['value'] && in_array( $option['option_name'], array( $choice['text'], $choice['value'] ) ) ) {
15+
$option['option_label'] = sprintf( '%s: %s, %s', $field->label, $choice['text'], $choice['value'] );
16+
}
17+
}
18+
}
19+
}
20+
return $product_info;
21+
}, 10, 2 );

0 commit comments

Comments
 (0)