update_product takes an item_id, not the order_id.
and the item id would be : order_item_id, from the wp_woocommerce_order_itemmeta table ?
That is strange since it does not update the quantity if I do that.
This is what I have now :
/**
* Update een order voor een klant
* @param int $userId user id
* @param int $orderNr order id
* @return bool return true or false
*/
function updateOrder($orderId, $data) {
var_dump($orderId);
/**
* Verander de order status
* @var WC_Order
*/
$order = new WC_Order($orderId);
$order->update_status($data['order_status']);
$order->update_product($data['metaId'], array('qty' => $data['order_item_qty']));
}
I can’t tell if metaId is valid from that paste.
You should also use wc_get_order() function, not the new WC_Order.
$orderId dumps : 340 << which also is shown in admin panel at orders.
$data[‘metaId’] dumps : 5 << which corrospodends with the order_item_id
So the correct code should be :
/**
* Verander de order status
* @var WC_Order
*/
$order = wc_get_order($orderId);
$order->update_status($data['order_status']);
$order->update_product($orderId, $data['metaId'], array('qty' => $data['order_item_qty']));
Ok so the update_product function should be written out like :
/**
* Verander de order status
* @var WC_Order
*/
// var_dump($data['metaId']);
// string(1) “5”
// var_dump($orderId);
// string(3) “340”
$order = wc_get_order($orderId);
$order->update_status($data['order_status']);
$order->update_product($data['metaId'], $orderId, array('qty' => $data['order_item_qty']));
No 🙂 Arg #2 is $product. It’s a product object.
You could just call the update directly you know:
wc_update_order_item_meta( $item_id, '_qty', wc_stock_amount( $args['qty'] ) );
Thank you very much for helping me that did the job.
And I actually did not see the wc_update_order_item_meta function on :https://docs.woothemes.com/wc-apidocs/.
I looked at the classes since that made sense to me.