Perhaps the way of @mrmarkuz could help to understand how it is working:
It is not about the certificate, but changing the vost configuration for each vhost.
I think you can change the function to your needs