Written for the author of this Facebook post. Jonathan wanted to conditionally show an element using the Oxygen conditions feature, if the user's ACF field 'webinar' had a certain value checked.
There were multiple values, with more potentially being added in future, so I wrote a function which took the value to be checked as an argument, and looked in the user's checkbox field for that value. If it's there, we return 1. If not, we return 0.
<?php
function sw_user_field_condition_check($compare) { // compare = the value you're checking
// check if user is logged in, if not, do nothing more
if(!is_user_logged_in()) {
return;
}
// get the users ID and save to variable
$user_id = get_current_user_id();
// get acf field
$checkbox_field = get_field('checkbox1', 'user_'. $user_id ); // this should be set to return values, in the ACF field settings
// check if compare value is in the array, and if so, return 1
if( $checkbox_field && in_array($compare, $checkbox_field) ) {
return '1';
} else {
return '0';
}
}
?>
Now you just need to make an Oxygen condition that uses this function. For example, when trying to show an element when 'checkbox1' is checked:
Done! Hope that was helpful. If you want any custom WordPress functions or scripts built, just send me an email to [email protected].