This was a time saver thanks to AI helper.
Use at your own risk.
// category post to product copy specific id's
function copy_specific_post_categories_to_product_categories() {
$args = array(
'taxonomy' => 'category',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'include' => array(76,77,78,79,80,81,82,83,87,88,89,90,91,91,92,93,94,95) // Add the category IDs you want to copy here
);
$post_categories = get_categories($args);
foreach ($post_categories as $post_category) {
$parent_id = $post_category->parent;
$cat_args = array(
'name' => $post_category->name,
'description' => $post_category->description,
'slug' => $post_category->slug,
'parent' => 0,
);
$cat_id = wp_insert_term($post_category->name, 'product_cat', $cat_args);
if (!is_wp_error($cat_id)) {
if ($parent_id > 0) {
$parent_term = get_term_by('id', $parent_id, 'product_cat');
if ($parent_term) {
wp_update_term($cat_id['term_id'], 'product_cat', array('parent' => $parent_term->term_id));
}
}
}
}
}
add_action( 'init', 'copy_specific_post_categories_to_product_categories' );
//