IMO if the Iran situation is limited to an air war, China should not get involved, even if the US joins in. Without boots on the ground, whatever government Iran ends up with and whatever shape it ends up in, it'll likely be more dependent on China.
If a ground invasion is being prepared, however, I think China does need to get involved. In the event of AR, I don't see the US coming near Chinese shores to try to contest the seas around TW, but rather attempt an embargo farther away in the IOR from Malacca to the ME and shores of Africa. To break that, China would need to "port hop", from Cambodia to Myanmar to Pakistan to ultimately IMO Iran. Land routes would also be established to those ports, and obviously that would be rather difficult if there are tens of thousands of American troops in Iran. As such, at first sign of a ground invasion, China should start building up assets in Afghanistan and Pakistan, to provide multiple routes of deployment into Iran.
The end goal should be a political solution, Iran promising to give up its nuclear program in exchange for Chinese guarantee of security. It should at least ostensibly satisfy all parties' needs, but certainly not everyone's wants. For Israel, the Saudis, and the West they get a denuclearized Iran, but Israel would be deeply disappointed at no regime change. For Trump in that situation it'd be better to call it mission accomplished rather than having a Chinese takeover in Iran. For Pakistan and Afghanistan they'd get much Chinese investment and support, while retaining their Iranian buffer from American/Israeli threat.