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

Trying to programmatically create variation galleries on product generation

Hi,

 

I have a script that procedurally/programmatically creates products with generated images, randomly generated skus, etc, and I’d love to replace my current gallery with individual galleries for each product.

My thought was to add $variation->set_gallery_image_ids($imagesArray) (where $variation= new WC_Product_Variation();) similar to the method for setting the gallery normally. My overall goal is to remove the standard image gallery altogether, and make it so that only the variations have galleries so that when someone selects a green product, they only see the green product images.

 

Best regards,

Andrew

Hakik Zaman

Hi Anderw,

Thanks for reaching out to us. Unfortunately, the feature you are looking for is not currently available.

​But it’s a great idea. Please send the feature request here: https://storepress.fider.io/

and ask your other to upvote it.

Thank You

This is entirely possible. Please refer to the following solution, found on separate thread:

https://wordpress.org/support/topic/adding-variation-gallery-via-php/

$variation = new WC_Product_Variation();
$variation->set_parent_id($product_id);
$variation->set_image_id($image_front);
$variation->update_meta_data(‘woo_variation_gallery_images’, $image_back);

Add this code before $variation_id = $variation->save(); but after $product_id = $product->save(); lines of code.

Hakik Zaman

Hi Anderw,

Thanks for sharing the code with us. Glad to know you have found a solution for this.

Thank You