I was an officer for a couple of different departments - one in Texas and one in California - back in the 70's, mainly deep nights.
As most of the others have said, it was usually 24-hour places that found it to be a good business practice to have officers around from time to time.
The business owners and the poor employees who had to work all night wanted to show their support for the police, and from my standpoint it was nice to feel appreciated - instead of getting the kind of attitude a lot of folks have for the law.
I frequented different places different nights at different times, as the calls allowed, mainly for my safety - habit patterns can be deadly. Thus, I didn't eat only where I knew there was a police discount. If there was, I always left a tip that came close to the price of the coffee or meal, but never said a word if the tab was for full price. Nor did I "set up shop" in any discount eatery. I took a my break and went back out, since I wasn't private security.
And if a I got a call, or heard something on the radio that got my attention I'd leave the meal uneaten. More than once my meal was uneaten because some idiot was so drunk that he totally missed seeing my car and me, and wandered in to cause a problem.
So, it's not like the HPD gets free gourmet meals just because of the uniform.