I can see few potential issues here:
-
wp_insert_post returns post_id or 0 or WP_Error, if you will have WP_Error it will still pass the
if ( $porduct_id )
. So here you have one potential issue. -
In description you wrote, that you create fields called “regions”, and in code you have
wp_set_object_terms($product_id, $regionId, 'region');
so here we have “region” no “regions”. Not sure if you misspelled in the code or in the description. -
Last thing is here:
<option value="<?php echo $child_category->term_taxonomy_id; ?>"
probably it should be$child_category->term_id
Hope any of this will point you to the issue.