This demo shows an example of how to extend existing Data Stores in WooCommerce.
NOTE: This is demo code and not even close to being something you want to use in production.
It extends an existing Product Data Store, and overrides only the inventory count, replacing the database count with one retrieved from an external API.
This plugin has everything needed to try out the example code.
- Set up a test WooCommerce site.
- Add 3 products with SKUs of "p120", "p121", and "p122", set stock quantities.
- Clone this repository under
wp-content/plugins
. - Under the
server
directory runnpm install
thennpm start
to run the test API server. - Activate the "WooCommerce Product Inventory Datastore" plugin.
- Observe the products with the SKUs above now receive inventory counts from the API instead of
wpdb
.