It is certainly a nice gesture if the person is happy for their groceries to be paid.
I was fortunate enough to be able to help someone at a chemist one day as they were slightly short and looked like not being able to buy her scripts. She was very happy but embarrassed and hoped she could pay...