I am creating a plugin that handles the full checkout for a WooCommerce cart.
It will do the payment and shipping and I simply need to then programatically create the order correctly in Woo Commerce.
I know I want to use wc_create_order(),
is there something I can then do to fill the order details from the current WC()->cart info?
And, as a 2nd part to this question, I will have a shipping address, how do I add that to the newly created order?
Here is what I ended up with:
$cart = WC()->cart;
$checkout = WC()->checkout();
$order_id = $checkout->create_order(array());
$order = wc_get_order($order_id);
update_post_meta($order_id, '_customer_user', get_current_user_id());
$order->calculate_totals();
$order->payment_complete();
$cart->empty_cart();
This question helped with the setting the user id part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With