You are correct .
Please tell how can i add order by Programmatically.
How to use wc_create_order ?
Because i am planing to create a new page for staff in which they can add customers order . Just putting the product id , product quantity , customer details etc . When they adding the order shipping charge need to calculate automatically . How to do this ? Is there any function to proceed this ?
For example :
Product id=1, qty=1
customer detail
first name: ddd
last name :rr
email : [email protected]
phone :123456
Address : addressxxxx
state :statexxx
paymentmethod: cash on delivery
Please tell which function i need to use .
I see the following code from stackoverfllow
https://stackoverflow.com/questions/26581467/creating-woocommerce-order-with-line-item-programatically
Please check this code is valid
$address = array(
'first_name' => 'Fresher',
'last_name' => 'StAcK OvErFloW',
'company' => 'stackoverflow',
'email' => '[email protected]',
'phone' => '777-777-777-777',
'address_1' => '31 Main Street',
'address_2' => '',
'city' => 'Chennai',
'state' => 'TN',
'postcode' => '12345',
'country' => 'IN'
);
$order = wc_create_order();
$order->add_product( get_product( '12' ), 2 ); //(get_product with id and next is for quantity)
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->add_coupon('Fresher','10','2'); // accepted param $couponcode, $couponamount,$coupon_tax
$order->calculate_totals();