Johnny Depp asked Sir Paul McCartney to make a cameo in 'Pirates of the Caribbean: Dead Men Tell No Tales' via text message.
The film's bosses were initially keen to secure Rolling Stones' Keith Richards to play a pirate rocker in the latest instalment of the adventure movie but when he was unable to film the part, the team were thrilled to secure the Beatles star.
Co-director Espen Sandberg said: "So we needed another rocker and on top of our list was Paul McCartney. And Johnny said, 'Well, I have his number.' And of course Johnny has Paul McCartney's number. So he started texting him. And it went back and forth. And then [Paul] said yes. So we were super happy."
Whilst co-director Joachim Ronning added to USA Today: "It was fun. And there we went."
Keith - who was unable to make a cameo in the most recent film due to "touring commitments" - had previously made an appearance as Captain Jack Sparrow's (Johnny Depp) father Captain Teague in 2007's 'Pirates of the Caribbean: At World's End'.
Sir Paul McCartney's involvement in the fifth installment of the pirate franchise was revealed in March 2016 when a source said bosses had approached the musician about the role and directors Ronning and Sandberg had decided to add an extra scene just for him.
Orlando Bloom is also returning in this instalment as 'Bootstrap' Bill Turner, after leaving the franchise in 2011's 'Pirates of the Caribbean: On Stranger Tides'.
He previously said: "There have certainly been some discussions about it and I'm open to it. That whole experience working with Johnny and (director) Gore (Verbinski) was really amazing for me. I had a great time working with Johnny, one of the reasons I jumped at the opportunity was because Johnny was involved."
Geoffrey Rush, Kaya Scodelario, Brenton Thwaites and Javier Bardem also star in the film.