Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

How to Successully Migrate your WooCommerce Store from Local/One Domain to another Domain/Remote Server

You can guess I have been doing more stuffs with WooCommerce. It is lovely working with a commerce system built into WordPress. I am not a wordpress person anyway but WooCommerce rocks. I think I should find some time to review Open Source Carts.

A friend asked me to help him move his WooCommerce store to another domain then it became clear to me that I have not had enough time with WordPress. I intentionally decided not to dive into WordPress despite all the buzz about it. Almost every new developer wants to discuss WordPress. This is a discussion for anoter time though. Let's get down to business. We want to migrate our WooCommerce Store to another domain.

Follow the following basic steps and thank me later

1. Tell WordPress the URL of your site has changed. Go to General Settings and change your home and site URL.

If you have already uploaded to your remote directory, go to your db and edit it from the siteurl and home URL under the wp_option (or dbprefix_option).

2. This is the larger part of the migration task. It is to update all the posts and custom fields to the URL of the remote server. We would need to do a bulk update of the links.

These MySQL statements will bulk replace your URLs. Obviously, you need to replace the sample URLs with your actual ones. 

  • UPDATE wp_options SET option_value = REPLACE(option_value, 'http://localhost.local', '') WHERE option_value NOT LIKE '%{%';
  • UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://localhost.local', '') WHERE meta_value NOT LIKE '%{%';

Warning: We’re going to bulk-edit the database next. Don’t do this before you’ve made backup of the entire database.

I’ve excluded keys that have the character { in them as they would be part of serialized arrays. If you replace parts of serialized data, the entire entry would become corrupt. These queries will replace only URLs outside of serialized arrays.

You also need to change the guid field in the wp_posts table.

  • UPDATE wp_posts SET guid = REPLACE(guid, ‘http://localhost.local‘, ‘‘);

3. Let's update the file path. Run below SQL query.

  • UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '/home/dev/wordpress', '/home/prod/wordpress') WHERE meta_value NOT LIKE '%{%';

Make sure you get the full path to the remote server or the domain you are deploying to.

Hope this puts smile on someone's face.

comments powered by Disqus