![](/img/trans.png)
[英]Wordpress (Woocommerce extension) - Create new order programmatically
[英]Programmatically create new order in WooCommerce
我们使用的是 Woocommerce 2.0.20.
版2.0.20.
我们正在尝试以编程方式创建新订单。
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);
}
但是当我调用这个代码顺序时没有创建。
wc_get_product
仅在 2.2.0 中引入。 如果您使用的是 2.0.2,请尝试使用get_product
(在 3.0 中已弃用)。
代码片段也不完整,因此很难诊断。 $productid
和$address
在代码段中为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.