We are using Woocommerce version 2.0.20.
We are trying to create a new order Programmatically.
add_action('woocommerce_checkout_process', 'myfunction');
function myfunction() {
$order = wc_create_order();
$order->add_product( wc_get_product($productid), 1); // This is an existing SIMPLE product
$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status("Completed", 'Order status', TRUE);
}
But when i call this code order is not created.
wc_get_product
was only introduced in 2.2.0. If you're using 2.0.2, try using get_product
(deprecated in 3.0) instead.
The code snippet is also incomplete so it's difficult to diagnose. $productid
and $address
are empty in the snippet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.