How can I only display variant images when the specific color is selected?

Thanks @PaulNewton where would I paste this code?