This example snippet assumes you're importing variations with a "color" attribute. You will need to adjust it if that's not the case for your products.
function wpai_image_imported( $post_id, $att_id, $filepath, $is_keep_existing_images = '' ) {
$product = wc_get_product( $post_id );
if ( ! $product ) return;
$parent_id = $product->get_parent_id();
if ( empty( $parent_id ) ) return;
$parent = wc_get_product( $parent_id );
if ( ! $parent ) return;
$existing = $parent->get_meta( 'woosvi_slug', true );
if ( empty( $existing ) ) {
$existing = array();
} else {
$existing = maybe_unserialize( $existing );
}
$slug = wc_sanitize_taxonomy_name( $product->get_attribute( 'color' ) );
$key = ( empty( $existing ) ) ? 0 : ( count( $existing ) + 1 );
if ( ! empty( $existing ) ) {
foreach ( $existing as $ikey => $value ) {
if ( $value['slugs'][0] == $slug ) {
$key = $ikey;
break;
}
}
}
$existing[ $key ]['slugs'][0] = $slug;
$existing[ $key ]['imgs'][] = $att_id;
$parent->update_meta_data( 'woosvi_slug', $existing );
$parent->save();
}
add_action( 'pmxi_gallery_image', 'wpai_image_imported', 10, 4 );