Stop it the same way you would if he were at home. If you usually give him a time-out, do the same when he goes nuts over a candy bar in the checkout line: Push your cart to the side and take him to sit in the car with you a bit. If, at home, you stop tantrums by distracting him with something, then do so at the store, too.
In other words, be consistent. He'll eventually figure out that you won't be embarrassed into giving him what he wants just because strangers are watching.
Ask Mom Squad expert Denene Millner your trickiest parenting questions at Parenting.com/momsquad.