How to Train Dogs to Refuse Food

Two people can cooperate; each person holds some treats on them, preferably the ones used for regular training. One person is responsible for holding the dog on a leash and waiting in place.
The other person goes to a farther place and places some regular training treats on the ground, in a location out of the dog's sight.
Then the person holding the dog walks past the treats on the ground as if taking the dog for a normal walk. If the dog eats the treats, immediately pull the leash and scold the dog sternly. At the same time, the other person goes further to place more treats on the ground. Then the dog is led past again. If the dog refuses to eat, the person holding the dog takes treats from their pocket to reward it. If the dog still eats, repeat the stern reprimand until the dog refuses to eat. If the dog refuses the treats on the ground, immediately give a reward from the pocket and praise.
This directly tells the dog "if you don't eat things on the ground, you will get pocket treats as a reward."
The number of successful trainings depends on the dog's intelligence. For breeds like Golden Retrievers, it can be trained in no more than three attempts. My dog Pipi only needed one time — one reprimand and one reward — and still maintains good behavior. For less smart dogs, just repeat a few more times; it’s not difficult.
Always carry treats in your pocket when going out for immediate training opportunities.
Also, it's better to develop a habit of playing when going out, rather than just going out to relieve themselves.
Focus on "playing" as the purpose of going out. Bring toys and play for a while at the destination. This focuses the dog's attention on playing, including on the way there, and the dog will know it’s going out to play, thus reducing attention to eating things on the ground.
One more tip: If the dog is particularly slow to learn and food refusal training is poor, buy a short leash about 50 cm long. Use that leash first when going out. It can prevent the dog from randomly eating and also helps with food refusal training. When the dog tries to eat something, pull the leash firmly. After many repetitions, the dog will understand.