For version 1.x.x documentation please see here »
For version 1 → 2 Migration Guide please see here »
This tutorial will describe how to install and set up Stock Sync for WooCommerce. The tutorial applies to both Free and Pro versions.
There are four necessary steps which we will go through:
- Installing the plugin
- Creating API keys for WooCommerce REST API
- Settings
- Initial synchronization of stock quantities
In addition there is troubleshooting section if you run into any issues. For example, stock discrepancies or failed syncing.
1. Installing plugin
First step is to install the plugin. It’s installed just like any other WordPress plugin.
- Download the plugin zip file
- Go to Plugins in the WordPress admin panel
- Click Add new and Upload plugin
- Choose the downloaded zip file and upload it
- Activate the plugin
You will need to install the plugin on all sites you want to sync.
1.1 Upgrading from Free to Pro
Upgrading from Free to Pro version is really simple:
- Activate Pro version
- Deactivate Free version
All settings will be preserved and Pro version works right away.
2. Creating API keys
Stock Sync for WooCommerce uses WooCommerce built-in REST API for communication between stores. First you will need to create API keys in all stores.
- Go to WooCommerce > Settings > Advanced > REST API > Add key
- Enter a description, select a WordPress user and set permissions to Read/Write
- WordPress user should have necessary permissions to edit product stock quantities, for example Administrator
- Take note of consumer key and secret
Repeat steps 1 – 3 for all stores.
3. Settings
There are two important settings you will need to make – 1) choice between Primary and Secondary Inventory 2) API credentials of other sites.
- Go to WooCommerce > Settings > Stock Sync
- Select if the site is Primary or Secondary Inventory. Please see below for differences.
- Enter the following settings under API Credentials
- URL – URL of the other store, for example https://store-a.com
- API Key – consumer key of the other store you created in the previous step
- API Secret – consumer secret of the other store you created in the previous step
- If you are setting up Primary Inventory, enter credentials of all Secondary Inventories. If you are setting up Secondary Inventory, enter Primary Inventory credentials.
- Click Check credentials to ensure they are correct
- Test function will create a test product to the other store via API and delete the product after that. This is required in order to check for read / write access. Other data is not affected.
Repeat steps 1 – 4 for all stores.
3.1 Primary vs Secondary Inventory
You should have one Primary Inventory and 1 – 9 Secondary Inventories. If you have only two sites you want to sync, it doesn’t matter much which site is Primary. However, if you have multiple stores, please consider the following:
- Primary Inventory should have all products which stock quantities you want to share.
- Complete logs are only available on Primary Inventory
- Tools are only available on Primary Inventory. Tools available:
- Push All – Pushes Primary Inventory stock quantities to all Secondary Inventories
- Update All – Fetches SKUs and stock quantities from Secondary Inventories and compares them to Primary Inventor
4. Initial synchronization
When settings have been completed, stock quantities should be pushed from Primary Inventory to Secondary Inventories. This will ensure stock quantities are same between all stores before you start syncing. Make sure Primary Inventory has correct stock quantities.
- Go to WooCommerce > Stock Sync > Tools > Push All
- Click Start pushing
- Wait until the process is complete. Do not close your browser or refresh the page.
- Only products with matching SKUs between stores will be pushed.
- Click View report » and check that stock quantities are matching
All done! When you edit stock quantities via admin, someone purchases a product or a refund is made, stock quantities will be synced between stores.
Tools
Tools are available at WooCommerce > Stock Sync > Tools on the Primary Inventory site. There are two different tools:
Push All
Push stock quantities of all products to Secondary Inventories. Use with caution! This will override stock quantities of matching SKUs on Secondary Inventories.
Update All
Update report by fetching SKUs and stock quantities from Secondary Inventories and comparing them to Primary Inventory. This can be used safely as it will not override anything.
Logging
Logs are available at WooCommerce > Stock Sync > Log on the Primary Inventory site. In the logs you will find:
- Possible errors in syncing process, for example invalid API credentials
- Successful sync jobs
- Failed sync jobs with error details
In addition to Primary Inventory logs, there are one kind of log messages you will find on Secondary Inventory. If syncing fails from Secondary to Primary (e.g. due to invalid credentials), log message will only appear on Secondary Inventory logs. This is because it’s not possible to send the log message to Primary Inventory if the initial connection fails.
Troubleshooting: Syntax error
In some cases “Syntax error” will occur when trying to sync stock quantities or validating credentials in the settings. The reason why it happens is that the other website responds in a non-standard way that cannot be handled correctly. There are a few common reasons why it happens:
- URL is invalid / doesn’t respond – try to visit with your browser and ensure it displays the URL correctly
- Some security / firewall plugin causes the error, such as Defender – disable security plugins temporarily and test again
- Another plugin is causing a conflict which results in an error – check PHP and WordPress error / debug logs
- SSL certificate is invalid – try with valid SSL certificate or disable SSL temporarily
- HTTP basic authentication is enabled which prevents connection – disable any HTTP basic auth
- Multilingual plugin such as WPML or Polylang is redirecting from base path (https://example.com) to language path (https://example.com/en) – try to add language code (e.g. /en) to the URL
The plugin will log the URL, response code and body which sometimes can give hint about the issue. You can view the log in WooCommerce > Status > Logs > woo-stock-sync-exception-x-x-x-xxxxx.log. The log is different from the basic log (WooCommerce > Stock Sync > Log). In the example below the reason is 404 error which means that the page couldn’t be found.
Information for developers
Stock Sync uses the following actions to monitor stock changes:
woocommerce_product_set_stock
woocommerce_variation_set_stock
These actions have to be triggered in order for Stock Sync to detect that stock has changed and successfully synchronize the change to the other sites. If you have developed a solution that updates stock quantities, make sure to trigger the actions appropriately.
Technically the plugin works similarly for both products and variations so you can only trigger woocommerce_product_set_stock
if you don’t know the product type.
Example of code that Stock Sync can’t detect:
function update_quantity( $product, $stock_quantity ) {
update_post_meta( $product->get_id(), '_stock', $stock_quantity );
}
This code won’t work because it doesn’t trigger the action after it has changed stock quantity.
Code that works with Stock Sync:
function update_quantity( $product, $stock_quantity ) {
update_post_meta( $product->get_id(), '_stock', $stock_quantity );
do_action( 'woocommerce_product_set_stock', $product );
}
This will work because it triggers woocommerce_product_set_stock
.