You know it’s not good for you, but it’s hard to break the habit. Many times you might not even notice you are doing it, getting up and going to the cupboard.
Have “beacons” that you can stick in or near the places you go to when you want a snack. Every time you approach any of these “beaconed” places your smartphone will alert you not to do it. You might even record a personal message that plays at that point. You can also have multiple messages, each one playing when you approach the “beacon” associated with it.