If you follow this forum post you can remove the interactive menu part, so while the layers are still technically there, they are stuck in their defaults, and user will not be able to turn them on/off from UI.
If that doesn’t work for you, then please elaborate on why flattening layers is important for you.
What do you mean exactly by the word “flatten”?
The more I understand your requirements the best I can assist. Input/output files, and screenshots help a lot also.