It doesn’t work like that with regards to taxing. What they do get is a good PR image at no cost to themselves (many places don’t match any donations[0]). Worse, some even keep a percent in “administrative fees” [1]
And there is concern that these checkout charities are replacing more traditional means of corporate giving, reducing net contributions.
Whether or not they make you feel ambushed, due diligence is worth hope before giving, as some companies (and the non-profits they give to) are more worthy than other.
[0] Such as walgreens. But there are some places, like Costco, that will match customer and employee giving.
I was under the impression that a corporation can take a tax deduction for charitable donations. There's a line item for it on Form 1120 (https://www.irs.gov/pub/irs-pdf/f1120.pdf)