Issue adding sub category programmatically

with this code we add a new main category

wp_insert_term( 'My New Category', 'product_cat', array('parent' => 0));

then knowing the category parent id we can add a sub category like so

wp_insert_term( 'My New Sub-category', 'product_cat', array('parent' => 72));

this is more or less what you have, but when I run the function get_terms I receive an array with two values, this means your variable $parent_cat_a would be something like this

Array
(
    [term_id] => 74
    [term_taxonomy_id] => 74
)

This means when you are calling $parent_cat_a, you arent recieving the parent id, you are just putting an array with more than one choice, worpress will not know how to use it, you should be calling $parent_cat_a[‘term_id’]

so where you have

$parent_cat_a = term_exists($myproduct['13'], 'product_cat');

I would replace it with

$parent_cat_aa = term_exists($myproduct['13'], 'product_cat');
$parent_cat_a = $parent_cat_aa['term_id'];

this probably will put your code to work, one more thing, like the first code above, inside the wp_insert_term() before parent you don’t need the slug, wordpress will put it for you, will check the category name and make a slug without spaces. its safer once you are putting the exactly same name.

tech