How can I create an Woocommerce Order Programmatically
You can use wc_create_order() to setup an Woocommerce order object and assign data you would like.
global $woocommerce; $address = array( 'first_name' => 'Test', 'last_name' => 'Test', 'company' => 'Test', 'email' => 'test@softwarehtec.com', 'phone' => '00-00-0000', 'address_1' => '0 test st', 'address_2' => '', 'city' => 'Test', 'state' => 'NY', 'postcode' => '10010', 'country' => 'US' ); $order = wc_create_order(); $order->add_product( get_product('1'), 1); $order->set_address( $address, 'billing' ); $order->calculate_totals(); $order->update_status("completed", 'Created order programmatically', TRUE);
Great Post! But how do i assign this order to an customer? And Update Status ‘completed’… isn’t it should be ‘wc-completed’?? And if you can please publish a post about how to trigger woocommerce payment process like checkout but it should process in the background!!
But how do i assign this order to an customer?
====================
Here is an example of how to assign an order to the customer.
https://softwarehtec.com/how-to-assign-an-woocommerce-order-to-customer-programmatically/
And Update Status ‘completed’… isn’t it should be ‘wc-completed’??
====================
It should be “completed”
please publish a post about how to trigger woocommerce payment process like checkout but it should process in the background!!
====================
Here is an example of how to trigger woocommerce payment process like checkout
https://softwarehtec.com/how-to-execute-woocommerce-payment-programmatically/