//link the product to the category
$cats = explode ( '|', $data[3] );
foreach ($cats as $cat){
$cat_taxs = explode( '->', $cat );
$parent = false;
foreach ( $cat_taxs as $cat_tax)
{
$new_cat = term_exists( $cat_tax, 'product_cat' );
if ( ! is_array( $new_cat ) ) {
$new_cat = wp_insert_term( $cat_tax, 'product_cat', array( 'slug' => $cat_tax, 'parent'=> $parent) );
}
$x = wp_set_object_terms( $post_id, (int)$new_cat['term_id'], 'product_cat', true );
$parent = $new_cat['term_id'];
//check out http://wordpress.stackexchange.com/questions/24498/wp-insert-term-parent-child-problem
delete_option("product_cat_children");
}
unset($parent);
}