This post details my experience with moving a live site from WooCommerce Multisite setup with two top level domains (TLDs) to one single TLD.  Throughout the process I referenced these two articles for help, but I found that they were both incomplete for my purposes; one from deliciousbrains.com and one from wpmudev.org.

The requirements for this move was to make the secondary domain (i.e. site id 2), the main single domain which is technically more challenging than making the base domain (i.e. site id 1) the one single domain.

Note: Before you start this process you should put your site in maintenance mode so no one can access it, there are plenty of WordPress maintenance mode plugins here is a link to one in the WordPress repo.

WooCommerce Multisite to Single Site – Step by Step

Step 0 – WooCommerce Site Backup

I call this step “0” because all sites should be backed-up, but unfortunately not all are.  If you do not have an automated backup system, manually create a backup of your whole website (i.e. the codebase and database).  Hosts such as WP Engine offer daily backups of the entire codebase and database, click here to learn more about WP Engine’s user portal. If you do not know how to backup your website contact your host for support, at the very least you should have backup of your database and “uploads” folder, since the “themes” and “plugins” folder will not be touched.

Step 1 – Download the site’s database

The WooCommerce Multisite (a.k.a Multi Store) setup duplicates a set of tables for each site.  Since our goal is to extract only one of the sites from the ones that exist, we must export the tables that are associated to that site, in my case site id 2, plus the user tables.

 

Using phpMyAdmin, click on your site’s database and then click “Export”.  You then want to keep all of the tables checked that include the id of your site, in my case id 2 so “_2_”.  You must then unselect all other tables other than “wp_users” and “wp_usermeta”:

 

Keep all other settings as is, scroll to the bottom on the page and click “Go”.  Your database should download locally, which could take up to a minute depending on the database size.

Step 2 – Edit the database table names

In this step we must rename the database tables from “wp_2_” to “wp_”, since they are going to be the main tables for the site as opposed to the secondary tables for an additional site.  Once the database has fully downloaded, open the “.sql” file in a text editor and do a search and replace from “wp_2_” to “wp_”.  This should replace the database table names only and nothing else within the file text.  Save the file and close the text editor.

Step 3 – Import modified database

Now that we have the “new” modified database for the single site, we must create a new database to import the tables into.  Create a new database in cpanel or your host’s admin panel and import the tables, via phpMyAdmin by selecting the new table and clicking “Import”.

Note: If you were using a Multisite subdomain or subfolder structure then you will want to change the URL values, in the database rows “siteurl” and “home” in the table “wp_options”, to the new single site URL.

Step 4 – Remove WooCommerce Multisite Configuration (wp-config.php)

In this step we will be removing the Multisite definitions and changing the database configuration to the new one we just imported in the previous step.  Find your wp-config.php file in the root of the website and open it in any text editor.

First, switch the database table to the new table and user that was created for that table:

define('DB_NAME', 'new_table_name');
define('DB_USER', 'new_user_name');
define('DB_PASSWORD', 'new_user_password');

Next scroll down and find the following code, which is used to setup the Multisite:

define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'my_site_com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Delete it, and replace it with the following code:

define( 'WP_ALLOW_MULTISITE', false );

Save the wp-config.php file and close it.

Step 5 – Edit your htaccess file

The “.htaccess” file resides in the root folder of your website.  Open it in a text editor and delete the following code:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress

Now add the following code instead:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Save and close the .htaccess file.

Step 6 – Copy the Multisite images to the single site

For this step we need a copy of the full Multisite “uploads” folder found at “/wp-content/uploads”.  Within that folder you will find another folder call “sites” and there you will find a number corresponding to the site id and an “uploads” folder within it (e.g. “/wp-content/uploads/sites/2/uploads/”).

What we now want to do is move the specific site uploads folder to be the main uploads folder since we are doing away with all other sites and their images.  I suggest you download a local copy of the “/wp-content/uploads” from a website backup you have and then via FTP, simply copy over “/wp-content/uploads/sites/2/uploads/” folder to “/wp-content/uploads”, replacing all of its contents and deleting the “sites” folder in the process.

Step 7 – Search and replace image links in Database

At this point you should be able to login to your “new” single site without any issues.  You will notice that you now only have a single site install and the Multisite Network has been removed.

Once logged in, I suggest installing the Search and Replace plugin so that you can replace any image links that are broken due to step 6.  Activate the plugin and go to “Tools->Search & Replace” and click on the “Search & Replace” tab.  You want to search for all instances of “/uploads/sites/2/” (or the site id in question) and replace them with “/uploads/”.

 

 

You probably want to “Dry Run” the first time to make sure search and replace was done correctly.  Once you are certain all fields are set correctly, uncheck “Dry Run” and select “Save changes to Database”.

Another step you might want to take if you are seeing broken images or your website is not loading correctly, is to search and replace the old main domain on the Multisite with the new single domain.

Step 8 – Save Permalinks

The final step which is simple but crucial, is to go to “Settings->Permalinks” and simply click save.  This ensures all of your links will work properly on your site.

WooCommerce Multisite to Single Site – Noteworthy

Once you have completed the steps above, you might still be seeing some weird behavior on your website which could be due to many different factors, here are somethings to check:

  1. Search your code base for hard coded links with the old base TLD included and replace them with the new TLD.
  2. Enable/disable plugins that might not be relevant anymore since your site is no longer a Multisite step.

Other tasks which you might need to consider:

  1. Copy tracking codes from Multisite installation to new single site installation.
  2. Redirect removed old TLD to new single TLD for SEO purposes.

Conclusion/Caution

Switching a WooCommerce Multisite to a single site is by no means a trivial task and the complexity of your setup could cause unforeseen issues, which is why the first step is to create a full backup of your website.  If you are not sure about some of the steps above, it is best to contact your developer or contact us to reduce the downtime to your website and ensure your website content is not lost.  That said, the steps above did work for us and should also work for most Multisite setups, either way comment below and let us know how the process went for you.

Leave a Reply

Your email address will not be published. Required fields are marked *