Some ideas:
There are browser extensions that you can get to block certain sites. (I wrote a custom one that I can use on my laptop, but I haven’t published it yet. I’m sure that there are others.)
If they are apps, you could uninstall the apps. I uninstall all non-essential apps that send me notifications.
Sometimes it helps to do just a little bit of something. Getting started is the hardest part, so tell yourself that you only have to do 5 flashcards. By the time you do 5 cards, you’re over the hurdle of getting started, and can often continue.
Atomic Habits is a good book.
Related discussions: