简体   繁体   English

在 WooCommerce 中以编程方式创建新订单

[英]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.

相关问题 Wordpress(Woocommerce扩展) - 以编程方式创建新订单 - Wordpress (Woocommerce extension) - Create new order programmatically 在 Woocommerce 中以编程方式创建新订单 - Programmatically creating new order in Woocommerce 在 Woocommerce 订阅中以编程方式创建订单 - Create an order programmatically in Woocommerce Subscription 在Woocommerce中以编程方式替换新订单电子邮件收件人 - Replace New order email recipient programmatically In Woocommerce 以编程方式将购物车内容添加到新订单(Woocommerce) - Programmatically add cart content to new order (Woocommerce) 在 Woocommerce 3+ 中使用订单项以编程方式创建订单 - Create an order programmatically with line items in Woocommerce 3+ WooCommerce以编程方式创建订单并重定向到付款 - WooCommerce create an order programmatically and redirect to payment 在 Woocommerce 中以编程方式创建新的产品属性 - Create new product attribute programmatically in Woocommerce 以编程方式创建的 WooCommerce 订单对新用户不征税 - Programmatically created WooCommerce order have no tax for new users 以编程方式创建“已完成”订单,无需将 email 发送给 WooCommerce 中的客户 - Create programmatically a “completed” order without sending email to customer in WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM