William caught up with Dave Martin on his pitch at a Tesco supermarket in Hammersmith, west London, on Tuesday.
He took Mr Martin, 60, a slice of his birthday cake and chatted to him about how he was doing, during the private visit.
The men got to know one another when the duke carried out a stint as a Big Issue vendor earlier this month. It allows the homeless to earn an income by selling the magazine.
William is the cover star of the latest issue and wrote an article about his experience, describing his time with Mr Martin, a Big Issue seller for 11 years, as “eye-opening”.
The duke has set out his key birthday as a turning point, pledging more help for those who are struggling.
He vowed to continue raising the issue of homelessness, in his article, and pledged to introduce his children to charities supporting rough sleepers, just as his mother Diana, Princess of Wales, did with him.
“I have always believed in using my platform to help tell those stories and to bring attention and action to those who are struggling,” he said.
“I plan to do that now I’m turning 40, even more than I have in the past.
“So, for my part, I commit to continue doing what I can to shine a spotlight on this solvable issue not just today, but in the months and years to come.”
The Duke and Duchess of Cambridge will reportedly hold a joint 40th party in the summer after the duchess’s birthday celebrations in January were cancelled due to rising Covid cases, according to the Daily Mirror.
Earlier, the duke issued a personal thank you for the birthday messages he received.
He wrote on Kensington Palace’s official Twitter account: “Thank you for all the happy birthday messages today!”
He signed his message “W”, meaning it had come from him personally.
The royal family wished William a happy 40th, sharing photos of his major milestones.
He was pictured on the monarchy’s Twitter account as a newborn, after his university graduation, at Sandhurst with the Queen, as a search and rescue helicopter pilot and on his wedding day.
Following a message reading “Happy Birthday to The Duke of Cambridge!” William was also shown surrounded by his three children, Prince George, Princess Charlotte and Prince Louis, in a snapshot recently released for Father’s Day.
The account also highlighted the duke’s charity work and his focus on the environment, young people and mental health.
The Prince of Wales and the Duchess of Cornwall also wished William a “very happy 40th birthday!”
Clarence House’s account shared photographs of Charles holding newborn William outside the Lindo Wing, on a ski-lift together, on the Palace balcony with the royal family, and William with his arm around Charles.