array loop of line items in woocommerce order REST

2019-08-24 19:32发布

问题:

i am tired of searching over couple of days for just a single working answer which is I want to loop array of line_items in woocommerce rest api of orders.

What I came too close is this https://wordpress.org/support/topic/how-to-pass-the-line_items-parameter-in-orders-rest-api/

One guy states Line items should be in array(array(item1), array(item2),....) format: item1,item2 increases by selecting multiple items in single orders in woocommerce rest api.

I have asked the same question here: Creating order Line items dynamically on Woocommerce Rest API

But i don't know why my question is downvoted for no reason.

I want to dynamically obtain this

    $order['line_items'] = array(
   array(
    'product_id' => 93,
    'quantity'   => 2
    ),
    array(
    'product_id' => 22,
    'variation_id' => 23,
    'quantity'   => 1
   ),
);

$results = $client->post( 'orders', $order );

Please an expert help would be much appreciated.