laravel-woocommerce
laravel-woocommerce copied to clipboard
Deduct from stock
Hello. Say I have 5000 of a certain product. I need a way to deduct from stock, programmatically. I didn't find a way to do so.
$data = [ 'stock_quantity' => //need to get actual stock and deduct from it (ie 'actual_stock - 5') ]; $product = Product::update($product_id, $data);
Also, I can't retrieve only the stock_quantity from an item.. how can I do that? Something like this:
$product = Product::find($product_id);
$product->get_stock_quantity();
Thanks in advance!
Hello @luizscaff
Thanks for creating an issue. I checked it works fine. At first you need to enable manage_stock and set stock_quantity. Follow below code
$data = [
'manage_stock' => true,
'stock_quantity' => 50
];
$product = Product::update($product_id, $data);
Above code enable stock manage and set your desire quantity. Now you can get the current quantity amount using below code
$product = Product::find($product_id);
$stock = $product->stock_quantity;
Hope your issue solved. Don't forget to press the star button if you like this package and if you want to encourage the contributors. Reply us if you face same issue and create new issue if you face another issue. We will try to solve your issue.
Regards, Md Abu Ahsan Basir
Thank you very much for your answer. I'm still a bit confused around programming. I see now what I was missing. Thanks again! :)
If you need further help you are always welcome. If you have another problem create a new issue. Thanks