In my site I need to change product's main image on customizable option change.

I have a text field customizable option. When it updates, I make a call to some URL and that URL returns me an image.

I need to set this image as main image for the current product, just for preview. I don't need to save the image in Magento. I just need to get the image as main image by adding it before other images of the product.

Is there any way I can do this?

1 Answer 1


You can use jQuery to do this, just check for change on the text field and update the main image with the image you get.

require(['jQuery'], function($){
    $('#textFiledId').on('change', function(){
        let src = 'img.jpg'; // get image using ajax 
        //set src to main image 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.