It was the Fourth of July, and the woman was hungry.

In the Whole Foods market in Manhattan’s Union Square, not far from New York University, the famished lady filled up three cardboard containers with food from the store’s buffet, stashed the grub into her bag and started to leave. A Whole Foods security guard nabbed the would-be shoplifter.

Then, three New York City cops arrived.

People of this city, take heart. Right there, in the pricey food emporium, something beautiful happened. And uplifting episodes like this one transpire ­every day, all across the United States.

The police not only didn’t ­arrest the woman; they didn’t give her so much as a harsh word or a cold stare. The three men on the job silently decided what they had to do: They paid the lady’s tab.

“I don’t do this all the time,” one of the officers, Lt. Louis Sojo, said a day later. “But when you look at someone’s face, and you know that they need you and that they’re actually hungry, it’s pretty difficult as a human being to walk away from something like that, you know? We weren’t raised like that.”

Cops perform random acts of kindness all the time, but you rarely hear about it. Not when the haters — chief among them New York City Mayor Bill de Blasio and his son, Dante — hog the megaphone.

In fact, Hizzoner has turned suspicion and contempt for law enforcers into a trendy campaign issue as he pursues a hopeless bid for president of the United States.

At the first candidates’ debate last month, he shamelessly dusted off an insulting story he told in 2014 about sitting down Dante, now 21, for “the talk,” lecturing the young man of color about ways to survive dealings with police, whom he painted with a broad brush as a gang of racist murderers.

As if the city’s first son has anything to fear from the men and women who would take a bullet for him, if need be.

It was pandering of the lowest order. And then, it got worse.

An op-ed column penned by Dante himself — years ago, his dad admitted — suddenly popped up in USA Today, recounting “the talk’’ he received from his dad and cousins and the terror he’s felt in the presence of police.

It was the worst kind of campaign theater, using Dante as a prop. Trouble is, though he recounted the terror he was instructed to feel, Dante’s essay never mentioned a single incident of mistreatment the young man suffered at the hands of cops, verbal or physical. He mentioned one incident in which a cruiser drove by him. That’s it: The officers did nothing to elicit his terror except pass him by.

The vast majority of cops are good, decent people performing incredibly difficult jobs, made even harder by those who make a sport of cop-bashing.

On July 4, staff at an Arizona Starbucks booted five cops from the java joint after a customer complained, irrationally, about feeling unsafe around them. This prompted coffee brass to issue an apology. But the damage was done. The mistreatment of police officers continues apace.

There are, of course, some bad police officers. Does that indict every person who wears blue?

Remember, it was police who stepped up and refused to bust a flurry of innocent African Americans whom racists tried to prevent from engaging in everyday tasks in the past months.

That included a black man who wore his socks poolside in Memphis, freaking out a white lady. Also, a group of African American women in Pennsylvania who played golf too slowly. In each case, the complainers were admonished for wasting officers’ time.

In a Philadelphia Starbucks last year, a white manager notoriously called police on two men of color who sat waiting in the store without buying anything. Those men were cuffed but never charged with any crime, an outrage that prompted thousands of Starbucks stores to close for a day of anti-racial bias training. It was the right thing to do.

But when will we see anti-cop bias training?

The officers who fed the hungry woman at Union Square weren’t seeking attention. The only reason the compassion of Lt. Sojo and Officers Esnaidy Cuevas and Michael Rivera received any notice was because a witness tweeted out a photo showing the lady sobbing in gratitude.

De Blasio, his son and all those who foment rage against the police owe the men and women in blue a heartfelt apology. But as long as bashing cops remains fashionable, and it earns de Blasio small poll bumps in his sleazy campaign, this won’t happen.