You can get the ID via a WooCommerce function – wc_get_product_id_by_sku
https://docs.woothemes.com/wc-apidocs/function-wc_get_product_id_by_sku.html
Then grab it using wc_get_product() and finally call $product->set_stock( X ) to set the stock value.
Doing it via SQL would require querying the postmeta table instead.
Thread Starter
brafal
(@brafal)
Thank you for the explanation, but I have to do it using SQL query, since that is the requirement at the moment. I am giving access to third-party service to change the quantity of a product (finding it by SKU) by accessing the database.
I’ve been looking for queries online for weeks but cant find anything. And since my SQL knowledge is limited, I am not able to write the whole query myself.
Thread Starter
brafal
(@brafal)
Or if there is alternative PHP code I could use to trigger quantity change by specific SKU and Stock Quantity.
^ what I showed you earlier was PHP. You’re going to be using the WordPress environment anyway so probably not worth using direct SQL.
I also have been needing to do this with SQL.
Currently I am returning a bunch of jason-type data.
i.e the following example from the SQL row/colum quantity by size:
a:5:{s:2:”XS”;s:1:”0″;s:1:”S”;s:1:”1″;s:1:”M”;s:1:”1″;s:1:”L”;s:1:”0″;s:2:”XL”;s:1:”0″;}
Not sure how to decipher this either. I am writing a plugin to export order and product data. I am down to my final query, which happens to require getting quantity per size per item.
Any thoughts?