You might also just pass 5 to 10 x 20 USD cash (or local equivalent) to the cashier and have that applied to the next person in line, and let them work out how to split any leftovers on their own.
I've never done either of those things myself, but I did feel horrid enough about our government during an extended shutdown over budget stuff to directly support the food bank with some 'staples' from Costco as well as a just outright cash donation back when that BS happened last.
Directly supporting the food bank is also an option that can help the even more needy.
But I think it's a good thing to do if you "hit" the correct "target".
It's feels good to genuinely do something nice for another person and I wouldn't want to take that from them. It's also nice just knowing that not everyone in your community is only looking out for themselves. Might as well take the opportunity to do something for someone else
I've wanted to pay sometimes for people - but didn't have the courage... shame.
I tend to just try help out those who are having trouble paying, regardless who they are, on the condition that if we're in a supermarket, their shop is a grocery shop on the whole; if they're buying £70 worth of spirits and nothing else, I'm probably not going to offer.
I work in central London, so sometimes a tourist will come into my local cash-only coffee shop just in front of me and not have cash, so I'll just offer to buy their coffees or whatever, though there are no cash-only coffee shops now since returning to the office after the pandemic, so it doesn't happen as often.
If they're struggling, card declined etc, they're probably already frustrated, they might turn to me to apologise, that's my cue; I'll just say, "hey, can I get that for you?“. I remember the first time, a guy about my age just buying food, his card was declined, he had a little bit of cash so the cashier was having him figure out what to leave behind so he had enough to cover it. I just asked if I could get it all for him and he just asked, "why?", looking puzzled, I just said "why not?", and something along the lines of "you can pass on the favour one day", he accepted.
Other times its that the place doesn't take cards and they need to get cash, I'll just say, they can add it to my bill and I'll get it, if they don't mind.
Sometimes people decline, but usually I'm pretty good at judging when people would appreciate it so it's rarely awkward.