Print

Skip WooCommerce Orders and Products

How to Prevent WooCommerce Orders and Products From Being Overwritten during Pushing

Whenever you use WP STAGING PRO to push changes from the staging site to the live website, you need to make sure that WooCommerce orders, customers, and products on the live site are not affected in any way and that they remain untouched.

So what is the best way to prevent those data from being overwritten during the pushing process?

The short answer is that you can not merely exclude this data from pushing your staging site, but fortunately, there is still a way not to lose your orders and products on the production site:

First of all, we need to understand where WooCommerce and WordPress store orders, product, user data like customer addresses, and all other data like posts and pages:

  • Orders and products are stored in the tables wp_posts and wp_postmeta separated by a custom post type field named ‘orders.’
  • WordPress itself also stores most of its data like pages, posts, and even menu entries and everything else in the same tables wp_posts and wp_postmeta
  • Users are stored in wp_users and wp_usermeta

There are also a bunch of other WooCommerce custom tables that contain data like tax rates, order items, and general WooCommerce settings.

Each staging site table name begin with the prefix  wpstg(x)_

The WooCommerce Table names begin with the same table prefix, but they also start with _woocommerce like wpstg(x)_woocommerce_

The x in the table prefix is the number of your staging site. So if you have multiple staging sites, that number will be counted up like wpstg1_, wpstg2_ And so on.

If you want to migrate specific data from your staging site to the production site without affecting any of the transactional data, you have three options:

Option 1) Export orders, user data, and other transactional data from the live site and import them into the staging site before migrating the staging site to live.
That allows you to copy the entire staging site.
That is the recommended way if you have no or less knowledge about the internal database structure. We explain below how this can be done.

Option 2) Exclude all database tables except the table _options and select only the plugins and themes folder you want to push to the staging site. Going this route way ensures that you never overwrite or lose data on the production site, which has been generated after creating the staging site. Most of the plugins also store their plugin settings in the table _options. So this will also migrate the plugin settings to the live site as well.
Important: Any other missing data which is included in the tables _posts and _postmeta the table needs to be created again on the live site by yourself manually after pushing.

Option 3) Exclude all modified database tables from the push process. If you go that route, you are not going to migrate the entire staging site, including all of its data!
Depending on the excluded tables (e.g., _posts, _postmeta), this can lead to missing images and even layout elements on your production website. Mainly if you use a visual editor like WPBakery (formerly known as the visual composer)  or Elementor because these editors store their designs in the tables _posts and _postmeta as well.

Note: Option 1 is the recommended way.

 

Option1: Export & Import WooCommerce Orders By Using Another Plugin

The best option is to export your orders and product data first by using a separate export/import plugin on the production site and then to import the data back into the staging site before you do the push.

Before you export and import any orders from your live site to live, it’s strongly recommended to create another staging site to test this whole process before you do the import and export on the real staging website!

 

Quickguide:

  1. Put your website in maintenance mode
  2. Use a plugin to export WooCommerce orders from the live site just before the push changes process.
  3. Import them into the staging site.
  4. Push changes from the staging site to the live one.

There are several plugins to do the exporting for you.
One plugin is Order Export & Order Import for WooCommerce.

(If you know another reliable import/export plugin, please let us know)

Keep in mind that exporting and importing orders could change the order id of new orders due to the reason that the WooCommerce order id is based on the post id, which is a unique number in WordPress.

So if the post id on your staging site is already used, the imported order gets a new id, which results in a new order id.

For most store owners, this might not be an issue, but if you need to keep the order id, you’ll need to use another plugin which adds a new database entry that stores the order id in a separate field and allows you to have that order id separated from the post id.

One plugin that can do it is WooCommerce Sequential Order Numbers.

Before you push the staging site, make sure to set your website into maintenance mode or to disable the shop system to make sure that no orders come in while you push data from the staging site to live.

Read also this ongoing in-depth and technical article about migrating WooCommerce orders from one site to another:

https://www.skyverge.com/blog/moving-woocommerce-orders-sites/

Option 2: Skip and Exclude WooCommerce Data from Pushing

Another option to exclude orders from being overwritten is to skip all the tables that include WooCommerce orders and products from pushing. You would need to exclude the tables below before you push the staging site to the production site:

  • wpstg1_posts
  • wpstg1_postmeta
  • wpstg1_users
  • wpstg1_usermeta
    All tables beginning with:
  • wpstg1_woocommerce_

Unfortunately, this table selection would also exclude posts, articles, and any other data that is stored in the tables _posts and _postmeta on our WordPress site. For instance, pages, posts, menu entries, and all other post related data would be excluded and not copied to the production site as well.

So, follow this step only this only when you are certain that you did not change any data on your staging site that you need to migrate over to the production site.

See also: WooCommerce database table reference.

Keywords: WP Staging + WooCommerce, WP Staging Exclude WooCommerce Orders, Exclude WooCommerce Products

Updated on September 12, 2020