''ze'' can be used most of the time. It sounds less formal but otherwise it's always a good alternative as long as the word is not stressed.
''hun'' is used instead of ''hen'' because it's the indirect object (dative case) and because no preposition is used. ''hen'' is used as a direct object or when a preposition is used.
You can determine the indirect object by asking (if I remember correctly) "to/for whom + predicate + subject + direct object'' which would be ''for who do we cook a meal?'', the answer is: for them.
This probably sounds rather complicated, which is why most native speakers mix up hen and hun all the time. So no need to worry about it really.
If you use 'voor ze' instead of 'voor hen' it is grammaticly incorrect. Don't do it, because if you do, you will be more likely to use 'hun' at the start of the sentence(s). Keep in mind, that lots of native Dutch speakers do so and are not aware of it. Please, do not copy their incorrectness.
Wij koken hun een maaltijd is not how a Dutch person would express cooking them a meal. First of all the use of hun is incorrect here. hun can only be used if it expresses a possessive adjective, p. ex. :it is their meal.. 'het is hun maaltijd'. 'Wij koken hun maaltijd' therefore would mean 'we are cooking their meal'.
So most important of all, if you are not sure about the difference between 'hen' and 'hun' remember 'hun' is about possessing something.
Louise, "hun" is not merely used in possessive forms! I don't know why you would say that. In general, you use "hen" after a preposition, e.g.: "ik geef het boek aan hen" or "wij koken een maaltijd voor hen". If you leave out the preposition, use "hun": "ik geef hun het boek" or "Wij koken hun een maaltijd". The sentence is correct. See an explanation in Dutch here: https://onzetaal.nl/taaladvies/hun-hen/
It is incorrect but within twenty years it will be correct as many Dutch use hun/hen wrongly. If you want to sounds Dutch better to use it incorrect as then you'll make the same mistake many Dutch make. Grammarly and officially hun is still wrong. Hun can only be used when talking about possession.
I see you're also taking German - not sure if you've gotten as far as the dative there, but the same idea here for hen and hun in the plural is what you find in German in the masc singular den - dem. hen is accusative (what are you cooking? I'm cooking a meal. meal=direct object). Hun is dative (for whom are you cooking the meal? I'm cooking them a meal. them=indirect object).