I need a little help. We want to connect our physical shop system with our virtual shop developed with woocommerce. So we need to be able to find where the SKU numbers are registred in the database so that we can do a batch process a few times a day to modify it as the products are physically sold (and not on the web).
But we haven't been able to find out where that number is registered in the WP database. Could someone help us?
I need a little help. We want to connect our physical shop system with our virtual shop developed with woocommerce. So we need to be able to find where the SKU numbers are registred in the database so that we can do a batch process a few times a day to modify it as the products are physically sold (and not on the web).
But we haven't been able to find out where that number is registered in the WP database. Could someone help us?
Share Improve this question asked Jul 17, 2020 at 14:06 federicofederico 211 silver badge2 bronze badges 2 |1 Answer
Reset to default 1As suggested in comments, the best way to update stock, or any other product information would be through the WooCommerce API.
The product endpoint with all the parameters is documented here (link is directly to how to update): https://woocommerce.github.io/woocommerce-rest-api-docs/#update-a-product.
I'm not very familiar with woocommerce, but based on other posts it looks like the stock value is stored in the _stock
key in wp_postmeta, see here for more info on that and how to e.g. convert between post ID and SKU if you need to. Again, note that not doing this through the API you might miss out on other code that gets triggered if WooCommerce would usually do other things (e.g. if stock is set to zero maybe it updates other fields automatically or triggers other events if you update through the API)
wp_postmeta
, where themeta_key = '_sku'
. If you plan to update data in the store though, you'd be much better served by using the REST API, rather than modifying the data directly: docs.woocommerce/document/woocommerce-rest-api Modifying the database directly means that no WooCommerce code will run for important actions when products are updated. – Jacob Peattie Commented Jul 17, 2020 at 14:19