Most grocery stores and Walmarts I've been to ask you how much cash back you want as one of the steps you punch in after you swipe your credit card. This happens after you have swiped your card so they know if it will be a credit or debit transaction. You pay $X extra, and receive $X in cash from the cash register with no fee.
Since the store has to pay a fee (e.g. $0.10 + 2% of the transaction amount) to the credit card company, why do they bother to put that option in front of your face? From the perspective of a corporation, the attention millions of people give to that screen as they complete their purchase is extremely valuable. Why wouldn't they at least offer some product/service that would earn them money?