fbpx
ūü§Ě¬† NEW YEAR SALE RETURNS - 50% OFF all plans! ūü§Ě Grab it Now

REST API Implementation

Hi,

Is it possible to send images to the variation gallery through the WooCommerce REST API and if you could give me a very basic example of how the data would look that would be very helpful.

Thank you,

Jonathan

Ahmed Ehsaan

Hi Jonathan,
We can develop it. Could you assist me? If you have tried API, could you confirm me that
is it possible to ad default image for variation using Rest API?
Thank You

Hi,

Yes, I am able to set the default variation image as well as the default image for the parent as well as the parent gallery with the REST API. I found this page where someone claimed they were able to get it to work by sending variant meta data. Any ideas of how to proceed with this?

Thank you

Emran Ahmed

Hello Jonathan Kelaty,

I added gallery response with REST API, when you retrieve variation product via REST API.

GET /wp-json/wc/v3/products/PRODUCT_ID/variations/VARIATION_ID

you will see that there is also woo_variation_gallery_images response available.

But seems you want to add images via API to the gallery. It’s also possible, Let me explain how.

Open  this file:

/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 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

Emran

Hi,

I was able to successfully add images to the variation gallery in my testing, but I have been doing it through image ID. How would you recommend uploading the images via the API and then getting the corresponding image ID’s so I can set them? I don’t see anything mentioned in the WooCommerce documentation about being able to directly manage media in WordPress. If you have any ideas, please let me know.

Thank you

Ahmed Ehsaan

Hi Jonathan,

If you found our support helpful, could you leave your valuable review here: https://wordpress.org/support/plugin/woo-variation-swatches/reviews/?filter=5

Your rating keeps us inspired.

Thank You