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_postmetaseparated 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
- Users are stored in
Many other WooCommerce custom tables contain data like tax rates, order items, and general WooCommerce settings.
Each staging site table name begin with the prefix
The WooCommerce Table names begin with the same table prefix, but they also start with
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
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 ensures that you never overwrite or lose data on the production site 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
_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 will not migrate the entire staging site, including 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.
Note: Option 1 is the recommended way.
Export & Import WooCommerce Orders
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 the whole process before you do the import and export on the primary staging website!
- Put your website in maintenance mode.
- Install plugin”WooCommerce Sequential Order Numbers” on production and staging site.
- Install plugin “Order Export & Order Import for WooCommerce” on production and staging site.
- Export WooCommerce orders from the production site.
- Delete all orders on the staging site.
- Import orders into the staging site.
- Push the staging site to the production site.
Step by Step Guide
Before you proceed, You’ll need to install two third party plugins:
You’ll need to install the “WooCommerce Sequential Order Numbers” plugin to ensure that the order numbers do not change on an import.
Exporting and importing orders could change the order id of imported orders for the reason that the WooCommerce order id is based on the WordPress post id, which is a unique number in WordPress. So if the post id on your staging site is already used by a post or any other item, the imported order would get a new id. So this could result in a new order id for an imported order.
So, to keep the order id intact as it is, you’ll need to use the plugin “WooCommerce Sequential Order Numbers.”
This plugin adds a new database entry to store the order id in a separate field. That allows your site to keep the order id separated and independent from the post id.
- Login to your production site
- Go to WooCommerce > Order Im-Ex
- Click on the “Export Orders” button:
This will generate a CSV file that you can store on your computer.
- Go to Your Staging Site WooCommerce > Orders
- Select all the orders there, then move them to the trash.
- Go to Your staging site
- WooCommerce > Order Im-Ex
- Check the “Update order if exists” box, then click on the “Import Orders” button and select the CSV export file:
After this step, all the orders should be imported into the staging site, and your staging site is ready to be pushed to the live site following this guide.
IMPORTANT: Sometimes, when you import orders into the staging site, a conflict might happen between order IDs and posts/pages/attachments IDs. This happens because you added new posts/pages or any other content on the staging site.
If that happened, you would see something like in this screenshot during the import process:
In that case, you will need to edit the exported .csv file using Excel or Libre Office calc software, for example. Modify the conflicting order IDs to any higher number that is not already in use by the post ids of your WordPress website:
Then re-import the file, and all the orders should be imported successfully.
Hint: You might need to do the same thing with WooCommerce Products or Users. For doing this, we recommend using these plugins:
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:
All tables beginning with:
Unfortunately, this table selection would exclude posts, articles, and any other data stored in the tables _posts and _postmeta on our WordPress site. For instance, pages, posts, menu entries, and other post-related data would be excluded and not copied to the production site.
So, follow this step only when you do 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