Cloning (Migrating) WooCommerce to a Different Domain

By Haktan Suren
In Blog
Dec 20th, 2015
0 Comments
1198 Views

Recently, one of my friends asked me to migrate his WooCommerce website to another domain without losing any data such as products (inventory), orders, WooCommerce settings (shipment, payment etc) and most importantly users.

After 3-4 hours hard work, I was able to migrate everything without any loss.

Before I was doing this by myself, I searched Google hoping to find some tools to make my job easier. However most of the tools looked promising was not FREE. From what I have found, I can give you the following two scripts that you can try if you have no coding experiences.

  1. Cart2Cart: WooCommerce to WooCommerce Migration/
  2. WooCommerce Settings Backup and Migration

I have not tested neither of them. However, from their description the first one seems to be doing the complete migration wheres the other one is just WooCommerce settings (shipment, payment, currency etc)

Now, we will continue for those who have coding experiences :).

The rest of the tutorial is based on phpMyAdmin.

Step 1: Copying the Products

SELECT `post_author`, 
       `post_date`, 
       `post_date_gmt`, 
       `post_content`, 
       `post_title`, 
       `post_excerpt`, 
       `post_status`, 
       `comment_status`, 
       `ping_status`, 
       `post_password`, 
       `post_name`, 
       `to_ping`, 
       `pinged`, 
       `post_modified`, 
       `post_modified_gmt`, 
       `post_content_filtered`, 
       `post_parent`, 
       `guid`, 
       `menu_order`, 
       `post_type`, 
       `post_mime_type`, 
       `comment_count` 
FROM   `wp_posts` 
WHERE  `post_type` = 'product' 

This query will list all the products (including their revisions etc). You can simply Export the DATA for the query and import it in your new db. I have excluded the ID field as it may conflict with the new DB. If you are migrating to a fresh DB. You can use ‘*’ without any problem.

SELECT post_id, 
       meta_key, 
       meta_value 
FROM   `wp_postmeta` 
WHERE  `post_id` IN (SELECT id 
                     FROM   `wp_posts` 
                     WHERE  `post_type` = 'product') 

The query above will list all the corresponding post_meta DATA related with the products. Here again, meta_id field is excluded for the same reason.

SELECT post_id, 
       meta_key, 
       meta_value 
FROM   `wp_postmeta` 
WHERE  `post_id` IN (SELECT id 
                     FROM   `wp_posts` 
                     WHERE  `post_parent` IN (SELECT id 
                                              FROM   `wp_posts` 
                                              WHERE  `post_type` = 'product')) 

You may need this last piece to complete the product migration if you have a product with product_variation.

Step 2: Copying the Orders

SELECT `post_author`, 
       `post_date`, 
       `post_date_gmt`, 
       `post_content`, 
       `post_title`, 
       `post_excerpt`, 
       `post_status`, 
       `comment_status`, 
       `ping_status`, 
       `post_password`, 
       `post_name`, 
       `to_ping`, 
       `pinged`, 
       `post_modified`, 
       `post_modified_gmt`, 
       `post_content_filtered`, 
       `post_parent`, 
       `guid`, 
       `menu_order`, 
       `post_type`, 
       `post_mime_type`, 
       `comment_count` 
FROM   `wp_posts` 
WHERE  `post_type` = 'shop_order' 

As you can tell, we are doing the exact same thing except this time the post_type is shop_order

SELECT post_id, 
       meta_key, 
       meta_value 
FROM   `wp_postmeta` 
WHERE  `post_id` IN (SELECT id 
                     FROM   `wp_posts` 
                     WHERE  `post_type` = 'shop_order') 

And again, the post meta for the orders.

Step 3: Product Categories

SELECT * 
FROM  `wp_term_taxonomy` 
WHERE  `taxonomy` =  'product_tag'

First is the taxanomies.

SELECT * 
FROM   `wp_terms` 
WHERE  term_id IN (SELECT term_id 
                   FROM   `wp_term_taxonomy` 
                   WHERE  `taxonomy` = 'product_tag') 

Next is the categories.

SELECT * 
FROM   `wp_term_relationships` 
WHERE  term_taxonomy_id IN (SELECT term_taxonomy_id 
                            FROM   `wp_term_taxonomy` 
                            WHERE  `taxonomy` = 'product_tag') 

And the last is their relationships with the products.

Step 4: WooCommerce Settings

SELECT * 
FROM   `wp_options` 
WHERE  `option_name` LIKE 'woocommerce_%' 

That’s it folks! Please leave comment if this post was any helpful.

About the Author

Haktan Suren
- Webguru, Programmer, Web developer, Graduate student & Father :)

Wrap your code in <code class="{language}"></code> tags to embed!

Leave a Reply

E-mail address is required for commenting. However, it won't be visible to other users.

Loading Facebook Comments ...
Loading Disqus Comments ...