Hello John
I tried to implement your code.
I see what you did there. Found image ID’s and put them in an array.
But they are saved incorrectly. Here’s how it looks like now:
(this product has 3 images)
<wp:postmeta>
<wp:meta_key>_product_image_gallery</wp:meta_key>
<wp:meta_value><![CDATA[a:3:{i:0;i:3688;i:1;i:3689;i:2;i:3690;}]]></wp:meta_value>
</wp:postmeta>