Tuesday 11th September 2018

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 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 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=<key1,key2>]

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=<key1,key2>]
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.

We design and develop all kinds of great stuff using WordPress, WooCommerce & LearnDash.

If you are looking for a new WordPress website, WooCommerce store or LearnDash LMS or want to improve an existing one, give us a call on 0114 303 8181 or click the button below to get the ball rolling.