fbpx
Want To Add Extra Images Per Product Variation For Free? Download Now

Rita Costa

Hi. I am trying to upload images at my variation via rest api. But when I upload the images, they don’t work. It does not upload the variation. But it uploads via CSV.

Is it possible to upload the images via csv

 

{‘regular_price’: ‘21.1’, ‘image’: {‘src’: ‘http://www.alphabroder.com/images/alp/prodDetail/01940e1_04_p.jpg’}, ‘woo_variation_gallery_images’: [{‘src’: ‘http://www.alphabroder.com/images/alp/prodDetail/01940e1_04_p.jpg’}, {‘src’: ‘ http://www.alphabroder.com/images/alp/prodGallery/01940e1_04_g.jpg’}, {‘src’: ‘ http://www.alphabroder.com/images/alp/prodDetail/01940e1_04_p.jpg’}, {‘src’: ‘ http://www.alphabroder.com/images/alp/backDetail/01940e1_bk_04_p.jpg’}, {‘src’: ‘ http://www.alphabroder.com/images/alp/sideDetail/01940e1_sd_04_p.jpg’}], ‘attributes’: [{‘id’: 4, ‘name’: ‘Size’, ‘option’: ‘M’}, {‘id’: 3, ‘name’: ‘Color’, ‘option’: ‘EC BLK CLSSC STR’}]}

Rita Costa

Hi,

 

I can not find this folder to make the alterations.

But if I understood correctly I have to upload the images ID at the meta data?

Isn’t there a clearer tutorial?

Tanvirul Haque

Sorry, Here is the file location /wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php

There is a function named prepare_object_for_database where woocommerce_rest_pre_insert_product_variation_object filter is available to receive your request. Now check how variation images are inserted. You will get an idea.

Remember that after processing your request you have to add image ids on woo_variation_gallery_images product meta.

Thank you

Rita Costa

Do you men adding this code to the function preapre_object_for_database?

add_filter( ‘woocommerce_rest_pre_insert_product_variation_object’, array( $request, ‘insert_update_v3’ ), 10, 3 );

Tanvirul Haque

Hello Rita Costa,

Yes, you are right, now you have to pass variation image ID’s as serialized data with this meta key woo_variation_gallery_images

Is there anything else that I can help you with?

Thanks