SOFIA VERGARA is getting married – but not before the “Modern Family” star secures an ironclad prenuptial agreement that will net her a cool $10 million if her playboy fiance NICK LOEB ever cheats!

And The ENQUIRER has all the thrilling details of the Emmy winner’s lavish plans for a splashy, Mexican beachfront wedding slated to take place during the Christmas holidays so that her 20-year-old college student son Manolo can give her away, say sources.

“Sofia’s shifted their nuptials plans into high gear and she’s completely consumed with every aspect of the event,” an insider told The ENQUIRER. “She says God is in the details and this wedding is going to be absolutely heavenly!”

The stunning actress has been walking on air since Nick’s July 10 proposal, but “she’s certainly keeping her wits about her in terms of an ironclad prenup that will hit Nick in the pocketbook if her ever strays again.”

The source said Sofia hammered out a $10 million payoff agreement if Nick cheats on her “and it escalates incrementally if she finds he’s been with more than one woman!”

The fiery Latina’s world was rocked this summer after The ENQUIRER revealed that her millionaire boyfriend, 37, cheated on her with prostitutes and strippers in cocaine-fueled orgies.

Nick managed to grovel his way back into her good graces and proposed to Sofia on her 40th birthday during a romantic makeup vacation in Mexico, where he pledged undying love AND fidelity.

Amazingly, Nick, whose first marriage ended in divorce in 2010, agreed to Sofia’s prenup ultimatum, paving the way for a spectacular tropical wedding.

“Sofia only agreed to marry Nick after he swore up and down he’d never again so much as flirt with another woman,” the source said. “The  bottom line is that Sofia is still crazy about Nick, but when he begged for her hand in marriage, she told him, ‘Put your money where your mouth is.’”

Nick, the son of a former U.S. ambassador and banking heir, is said to be worth $15 million, “so if there’s ever an indiscretion on his part during the marriage, he’d pretty much be cleaned out,” the source added.

“Now Sofia is desperate to put the past behind her. She accepted Nick’s apology and the wedding’s on!”

The happy couple is said to be planning a beachfront ceremony at sunset with hundreds of guests. Sofia has been in constant contact with Vera Wang about designing the gown, and she’s planning a pan-global menu with Mexican, Japanese and Italian food.

“The wedding is going to be a huge blowout,” predicted the source. “And now Sofia has peace of mind that if the marriage goes south due to cheating, at least Nick  will pay handsomely for it.”