How we avoid this (I shop only once every 1-3 weeks):
-stock up on shelf-stable produce -- i.e. apples, oranges, sweet potatoes, onions, etc. that don't go bad quickly
-fill the freezer with frozen fruit & veggies
-make your own bread, or buy an extra loaf or two & freeze it
-keep dairy-free milks (like tetra-packed almond milk, or cans of coconut milk, or nuts to make your own nut milk) that you can switch to mid-week when you run out of dairy milk
We live off fresh stuff for a week or so, then switch to mostly freezer/pantry for the second week. So no mid-week stops for groceries -- saves time, gas, and money.