First ideas came with magnets tied some way to the razor, but implied modifications on each new razor.
Finally I found this simple and cost effective solution, and the cap should fit to any new foam bottle
What is needed:
* 1 x nylon tie
* 1 x O-ring (big enought for your razor)
* Under 1Eur/1USD
* Drill on the cap two vertical holes with a heated screwdriver tip
* Insert the flange, keeping the head of the tie inside the cap and the o-ring outside
* Add colour o-rings if more family members use the same foam
We are done. Enjoy finding your razor everyday in the same place.