How to make product image change after choosing a configurable option on the product listing page?

How to make product image change after choosing a configurable option on the product listing page?

Configurable products are assembled from simple products, which represent variations of the same item. Each simple product can have its own image that differs it from other options. For example, you can upload images of different color variations of the same product. When customers look through the catalog, it's more handful for them to see what the color looks like right after they select a color option on the catalog page instead of going to the product page.

Default Magento does allow changing product images when selecting a configurable option. To enable this functionality, go to Stores → Attributes → Product → choose the attribute (e.g., color) → Properties tab and enable the Update Product Preview Image setting. 





As a result, the product images change according to the chosen color option: 




Moreover, this setting is also responsible for changing the image when the corresponding navigation filter is applied: