The function is to get incremental sales (and hopefully establish a pattern of repeat business) by discounting selectively to people who might not buy at all otherwise.
If you're thinking "But they should give that discount to everybody!" that's not a thing. There's not enough margin in the first place, especially at a supermarket or Walmart, that everyone could just have lower prices on everything.
My grocery store already sends me individualized paper coupons every month.
All of this is promotions. It's all just trying to get some incremental sales, and hoping that if you get an offer for free hot dog buns you'll also buy the hotdogs.