[英]Programmatically create new order in WooCommerce
We are using Woocommerce version 2.0.20.
我们使用的是 Woocommerce
2.0.20.
版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. wc_get_product
仅在 2.2.0 中引入。 If you're using 2.0.2, try using get_product
(deprecated in 3.0) instead.如果您使用的是 2.0.2,请尝试使用
get_product
(在 3.0 中已弃用)。
The code snippet is also incomplete so it's difficult to diagnose.代码片段也不完整,因此很难诊断。
$productid
and $address
are empty in the snippet. $productid
和$address
在代码段中为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.