You can find the Advanced Custom Fields fields which you added in the $_POST array under the ‘fields‘ key. Use ACF’s get_field_object() function to get the key of your field you added.
So if you named your field ‘nr_available’, you have to find its key to be able to find this field in the $_POST object (so you can fetch $_POST[‘fieldKey’]).
Check the following code:
function update_course($course_id)
{
$nr_available = 0;
$nr_registered = 0;
$field1 = get_field_object('nr_available');
$nr_available_key = $field1['key'];
$field2 = get_field_object('nr_registered');
$nr_registered_key = $field2['key'];
// loop the $_POST['fields'] which contains all the Advanced Custom Fields fields which you added to the post you are editing
foreach ($_POST['fields'] as $k=>$v)
{
// $k are the custom fields keys
// $v are the custom fields values
if ($k == $nr_available_key){
$nr_available = $v;
}
if ($k == $nr_registered_key){
$nr_registered = $v;
}
}
// Do your checks after you get the values
if ( ($nr_available > $nr_registered) || $nr_available <= 0 )
{
// Bad
return;
}
}
add_action( 'edit_post' , 'update_course');