Since the WHO_AM_I register content is the same for both devices, in order to discriminate them in code I suggest you to poll -for example- the CTRL_REG0 (1Eh) register. It exists and is 00010000bin for the LIS2DH12, while it doesn't exist for the IIS2DH. See LIS2DH12 datasheet, p.33.
If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.
ok, that was unexpected. It had changed in time. You might then try reading the FIFO_SRC_REG (2Fh), that should be 0010000b for the IIS2DH, and 0000000b for the LIS2DH12.
Otherwise, the only way to distinguish between them is from the top package marking.