I agree with everyone who has cautioned you not to disable write caching. However, should you really want to do so, here’s the article to read:
https://wiki.archlinux.org/title/hdparm
In particular, read these sections:
https://wiki.archlinux.org/title/hdparm#Write_cache
https://wiki.archlinux.org/title/hdparm#Persistent_configuration_using_udev_rule
Warning: What I write below has not been tested by me, and I may be completely wrong. Experiment at your own risk.
Assuming that you want to disable write caching only for non-rotational drives, my guess is that you would do the following…
Create this file:
/etc/udev/rules.d/69-hdparm.rules
Then add this code to the file:
ACTION=="add|change", KERNEL=="sd[a-z]", ATTRS{queue/rotational}=="0", RUN+="/usr/bin/hdparm -W 0 /dev/%k"
Assuming that you want to disable write caching for all drives, even rotational drives—which would be an even worse idea, in my opinion—my guess is that you would add this code instead:
ACTION=="add|change", KERNEL=="sd[a-z]", RUN+="/usr/bin/hdparm -W 0 /dev/%k"