Bulk Move Woocommerce Categories Under Specific Parent

Use at your own risk. If you don’t know where this goes you should not be even attempting to use this.    
				
					

/// bulk move under a specific category parent by ID's

function bulk_set_product_category_parent() {
    $parent_category_id = 149; // Replace with the ID of the parent category
    $args = array(
        'taxonomy' => 'product_cat',
        'hide_empty' => false,
        'include' => range(184, 200), // Range of category IDs to update
    );

    $categories = get_categories($args);

    foreach ($categories as $category) {
        $category_id = $category->term_id;
        wp_update_term($category_id, 'product_cat', array(
            'parent' => $parent_category_id,
        ));
    }
}

add_action('admin_init', 'bulk_set_product_category_parent');

				
			

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment