Add class to specific li item menu in function.php

To add CSS classes to menu item li, use filter nav_menu_css_class (codex).

add_filter('nav_menu_css_class' , 'hideMenuItem' , 15 , 4);

function hideMenuItem($classes, $item, $args, $depth) {

    $commerce = get_field('ecommerce', 'option');
    if ( !$commerce ) {
        $menu_items = array(566, 567, 363, 364 );
        if ( in_array($item->ID, $menu_items) ) {
           $classes[] = 'hidden';
        }
    } 
    else {
        $menu_items = array(566, 567);
        if ( in_array($item->ID, $menu_items) ) {
            $classes[] = 'visible';
        }
    }
    return $classes;
}

error code: 521