A heterostructure is composed by two different materials like pn junction. The work function refers to the potential difference between the interface of a heterostructure.
During optimization turn on LVTOT = .TRUE. in INCAR to calculate the local potential. You then visualize the local potential and program to read the local potential to compute the vacuum level, then the work function. Furthermore, I am sending you attached script. After optimization use the script vtotav but you should remove the symbol of atoms from LOCPT (output file after optimization) or use vaspkit
workfunction= vaccume potential- Fermi Level (obtained from OUTCAR, less OUTCAR the /E-fermi)