Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce Add item to Order

I'm trying to add an item to an existent order but it's not working properly... Everytime I execute the code below it ads and empty item, any help?

woocommerce_add_order_item($Novo_PostId, $item);

$item is the var witch receives the item itself from another order I have, I've put a print_r($item) and it appears to be ok.

like image 231
Douglas Soares Avatar asked Dec 08 '22 15:12

Douglas Soares


1 Answers

Since WC 2.2, adding an item to a new order is simpler:

 $product = wc_get_product($product_id);

 wc_get_order($order_id)->add_product($product, $quantity);
like image 199
Aaron Harun Avatar answered Dec 11 '22 09:12

Aaron Harun