I remember as a small child in the 1960's, being the youngest, I was regularly required to crawl under the stall and unlock it for my mother, who then held it open for each sister and for my brother young enough to be in the ladies room, and finally I'd get to go. If I actually needed to go, I'd go before letting my mother in.
A few years later, much to my delight, restrooms became a right and not a privilege. A business which doesn't sell food may refuse to let patrons use their facilities, but if they sell food for consumption on site, free public restrooms are required, at least in Texas.
As for the other businesses, they quickly fell into line. When I was almost 9 months pregnant with my first child, who weighed nearly 9-1/2 pounds at birth, I was shopping in a pharmacy. I had prescriptions I was going to fill, and needed several other items. Rather than going to the supermarket across the parking lot, I thought I'd get the all there. They told me there were no public restrooms. I pointed out they catered to sick people, people with sick kids, and pregnant women.
I left my full cart, drove across to the supermarket, and bought everything there. I had the prescriptions filled at another pharmacy. I told their management why I had chosen that pharmacy. After enough people did that at enough places, it's rare to find any business other than perhaps a small jewelry store or other one-person operation which doesn't provide facilites.