set a parent category in a product woocommerce

If you already got term object at $data[1] then you can simply access the parent by doing this-

$parent_id = $data[1]->parent;

If you got only term ID then you need to do-

$term = get_term($data[1], 'product_cat');
$parent_id = $term->parent;

After getting the parent term ID you can simply assign the product to the parent ID by doing-

wp_set_object_terms($product_id, $parent_id, 'product_cat', true); 

Update: Now your previous category data will not be replaced.

Hope that helps.