I am using "Programmatically creating new order in Woocommerce" answer code and I want when I clicking button that an order comes to admin panel.
Here is my attempt:
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'new_order':
new_order();
break;
}
}
function new_order() {
global $woocommerce;
$address = array(
'first_name' => $shippingName,
'email' => $user_email_id,
'phone' => $billingPhone,
'address_1' => $shippingAddress,
'address_2' => $shippingAddress2,
'city' => $shippingCity,
'state' => $shippingStateCode,
'postcode' => $shippingZip,
'country' => 'US');
);
$order = wc_create_order();
$order->add_product( get_product());
$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status("Completed", 'Imported order', TRUE);
}
And My button:
<input type="submit" id="button" name="new_order" value="Submit" >
Is that the correct way? Any Help is welcome.