Skip to content

Commit 7a71370

Browse files
authored
gppa-use-acf-choice-label.php: Added new snippet.
1 parent 3e4e732 commit 7a71370

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Populate Anything // Use Advanced Custom Field's Choice Label
4+
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
5+
*
6+
* By default, Populate Anything will populate the value of any choice-based ACF custom field that is mapped. This snippet
7+
* allows you to populate the label of an ACF choice (e.g. Radio Button, Checkbox, etc) instead.
8+
*
9+
* Instructions
10+
*
11+
* 1. Install the snippet.
12+
* https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
13+
*
14+
* 2. Add the CSS class "gppa-use-acf-choice-label" to the CSS Class Name field setting for any field that should use the
15+
* ACF choice label.
16+
*/
17+
add_filter( 'gppa_process_template_value', function( $template_value, $field, $template_name, $populate, $object, $object_type, $objects ) {
18+
19+
if ( strpos( $field->cssClass, 'gppa-use-acf-choice-label' ) === false ) {
20+
return $template_value;
21+
}
22+
23+
$label = get_field( str_replace( 'meta_', '', $field->{'gppa-values-templates'}['value'] ), $object->ID );
24+
25+
return $label;
26+
}, 10, 7 );

0 commit comments

Comments
 (0)