This blog post summarizes the science nicely: …stanford.edu/…/a-conversation-about-the-science-…TL;DR: You can train your willpower. It does act like a limited resource [Edit: Science is inconclusive on this claim]. But most importantly, it is strongly affected by your sleep, nutrition and stress level.
I found that mindfulness meditation was helpful for me. Practically, you can achieve an effect that is similar to having strengthened willpower by organizing your life in such a way that you don’t encounter many temptations in the first place.