First, collect the category and the related data such as name, thumbnail, description, slug, parent id, etc.
Now use the foreach loop to go through all the categories. Use fetch_media() to get the thumbnail id and wp_insert_term() function to create the product category.
Update the thumbnail id with the category id with the help of update_term_meta() function.
$cats = array(
array('thumb' => 'images/uploads/cat09.png','name' => 'Cat 9','description' => 'Cat 9 description','slug' => 'cat-9','parent' => 8),
array('thumb' => 'images/uploads/cat10.png','name' => 'Cat 10','description' => 'Cat 10 description','slug' => 'cat-10','parent' => 8),
array('thumb' => 'images/uploads/cat11.png','name' => 'Cat 11','description' => 'Cat 11 description','slug' => 'cat-11','parent' => 8),
);
foreach($cats as $data) {
$thumb_id = fetch_media($data['thumb']);
$cid = wp_insert_term(
$data['name'], // the term
'product_cat', // the taxonomy
array(
'description'=> $data['description'],
'slug' => $data['slug'],
'parent' => $data['parent']
)
);
if(!is_wp_error($cid)){
$cat_id = isset( $cid['term_id'] ) ? $cid['term_id'] : 0;
update_term_meta( $cat_id, 'thumbnail_id', absint( $thumb_id ) );
}
}