Hi @ysnz
It’s a bit complicated but here’s the code snippet to achieve the Key-Pair values for checkbox:
function um_021821_checkbox_array(){
return [
'apple' => 'Apple',
'banana' => 'Banana',
'carrot' => 'Carrot'
];
}
add_filter("um_field_checkbox_item_title", function( $um_field_checkbox_item_title, $key, $v, $data ){
if( $key == 'key-pair' ){
$arr = um_021821_checkbox_array();
$um_field_checkbox_item_title = $arr[ $v ];
}
return $um_field_checkbox_item_title;
}, 10, 4);
add_filter("um_edit_key-pair_field_value", function( $value, $key ){
$arr = um_021821_checkbox_array();
return $arr[ $value ];
}, 10, 2);
add_filter("um_profile_field_filter_hook__key-pair",function( $value, $data ){
$arr = explode(", ", $value );
$arr_reference = um_021821_checkbox_array();
$arr_new_format = [];
foreach( $arr as $a ){
$arr_new_format[ ] = $arr_reference[ $a ];
}
return implode(", ", $arr_new_format);
},10, 2);
key-pair is the name of the checkbox field so you will have to change it in the code snippet above to match your field’s meta key.
um_021821_checkbox_array is function where you add the key-pair. You also need to add the values to the checkbox options via Form Builder. Use the slugs( e.g. apple, banana etc. ) as option values.
Regards,
-
This reply was modified 5 years, 2 months ago by
Champ Camba.
Hi @ysnz
Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂
Regards,