hello I want to know how to add multiple products in a order using coding. I'm currently using this code
$address = array(
'first_name' => 'random',
'last_name' => 'random',
'company' => '',
'email' => 'random@random.com',
'phone' => '987987987987',
'address_1' => 'hawa hawa havai',
'address_2' => '',
'city' => 'Delhi',
'state' => 'New Delhi',
'postcode' => '11447788',
'country' => 'IN'
);
$order = wc_create_order();
$order->add_product( wc_get_product('819'), 2 ); //(get_product with id and next is for quantity)
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();
I'm successfully able to add one product but how to add multiple products at same time. I tried this code but doesn't helped.
UPDATE 1
this code works
$order = wc_create_order();
$order->add_product( wc_get_product('819'), 2 ); // 819, 815... etc are product id.
$order->add_product( wc_get_product('815'), 1 ); // 2, 1, 3 are quantity of products.
$order->add_product( wc_get_product('835'), 3 );
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();