Cockpit visits normally occur on the ground. It's a big ask to do this in flight and most airlines would forbid having nonemployees in the cockpit at any point during the flight, although the captain might have discretion on some carriers for people that he/she knows well. It's considered a huge security risk..