PWM-safe 24V to 12V fan adapter (optocoupler + MOSFET)

How to connect a 12V fan to a 24V 3D printer, maintaining the PWM speed control?
My circuit was built using salvaged components from an old PC power supply.

Material:
R1: 10KOhm
R2: 1.2-1.5KOhm
Q1: any N-channel enhancement MOSFET (I used 2N60C)
OPTO: any 4-pin optocoupler (I used EL817)

How does this work?
R2 value has been chosen to get an optocoupler voltage voltage of ~1.2V and a current of ~20mA when 24V is applied.
R1 is 10K in order to keep the MOSFET gate at 0V when the fan is off.
When the 24V fan turns on, the optocoupler connects the MOSFET gate to 12V, which is greater than VGS_thr of 4V but less than the maximum VGS allowed of 30V: the MOSFET becomes a closed circuit, powering the fan.
This circuit allows the PWM modulation to be transferred to the 12V power source.