---
title: "Recategorising thousands products in an e-Commerce store."
date: 2018-09-11
author: "Dave Pullig"
featured_image: "https://www.deliciousmedia.co.uk/content/uploads/2018/09/wordpress-clone-taxonomy.jpeg"
categories:
  - name: "WooCommerce"
    url: "/category/woocommerce.md"
  - name: "WordPress"
    url: "/category/wordpress.md"
  - name: "WordPress Development"
    url: "/category/wordpress-development.md"
  - name: "WordPress Plugins"
    url: "/category/wordpress-plugins.md"
---

# Recategorising thousands products in an e-Commerce store.

As part of a redesign of their WordPress based e-Commerce store, a customer of ours needed to recategorise tens of thousands products. Due to their setup, this had to be done on their live site, so carrying out the work on a staging site and copying up the database wasn’t an option.

We decided the best solution was to create a second, “product categories” taxonomy for their content team to work on in preparation for their relaunch while leaving the original in place and active. To give them a good starting point, also we needed to copy the existing category structure (around 450 categories/subs-categories) along with term metadata for each of the terms over into the new taxonomy. They also had some old category metadata which was no longer required so we added the ability to skip certain meta keys.

Surprisingly, we couldn’t find an existing solution, so we built a tool to do it. We’ve released the tool we built as [DM Clone Taxonomy](http://github.com/DeliciousMedia/DM-Clone-Taxonomy) which does just that.

Although it is a WordPress plugin, it doesn’t currently provide an interface within the WordPress admin area, it’s a [WP CLI](http://wp-cli.org/) command so it likely to be more suitable for more advanced users or WordPress developers. That said, it’s very simple to use – here’s the documentation:

> **NAME**
> 
> wp clonetax
> 
> **DESCRIPTION**
> 
> Clones taxonomy data (terms, term meta and post relationships) from one taxonomy to another.
> 
> **SYNOPSIS**
> 
> wp clonetax \[–post\_type=\] \[–skip\_meta\_keys=&lt;key1,key2&gt;\]
> 
> **OPTIONS**
> 
> The source taxonomy to copy data from.
> 
> The target taxonomy to copy data in to. This taxonomy cannot contain any existing terms.
> 
> \[–post\_type=\]  
> Name of the post type to copy term relationships for (default: post).
> 
> \[–skip\_meta\_keys=&lt;key1,key2&gt;\]  
> Comma separated list of term meta keys that should not be copied (default: none).
> 
> **EXAMPLE**
> 
> wp clonetax *product\_category* *new\_product\_category* –post\_type=*product* –skip\_meta=category\_alt\_name

In the example above, we’re copying the *product\_category* to the *new\_product\_category* taxonomy, updating posts with the type *product* so they are in the same categories in *new\_product\_category* as they did in *product\_category.* We are also copying across term metadata, but and ignoring the term meta *category\_alt\_name* as we no longer require that.

In terms of migrating from one category structure to another, here’s how we’ve approached it:

- Create a new taxonomy (“product\_category”) which is hidden on the frontend.
- Duplicated existing taxonomy data using our tool.
- Replace all references to the existing category (“store\_product\_category”) in code with a constant DM\_PRODUCT\_CATEGORY and set that constant to the old taxonomy name to allow us to switch between taxonomies during testing.
- Hand over to client’s content team to update their content.
- When ready to launch, modify the old taxonomy so it is no longer visible on the frontend and set the new taxonomy’s slug to be the same as the old one. Switch the DM\_PRODUCT\_CATEGORY constant over so the site uses the new taxonomy on the frontend.

You can download [DM Clone Taxonomy from our GitHub page](http://github.com/DeliciousMedia/DM-Clone-Taxonomy).