在结帐页面中更新 woocommerce 订单以创建一个新订单 [英] updating woocommerce order in checkout page instead to create a new one

查看:35
本文介绍了在结帐页面中更新 woocommerce 订单以创建一个新订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Wordpress 和 WooCommerce 插件,它执行以下操作:

I am creating a Wordpress and WooCommerce plugin which does the following:

  1. 匿名用户自定义页面上的产品
  2. 在一个php脚本的过程中,它在数据库中创建一个订单
  3. 用户转到要求提供客户数据、交货等信息的结帐页面.

通过点击立即购买",WooCommerce 在系统中创建一个新订单,我想要的是在个性化过程中更新之前创建的订单,添加客户详细信息、付款、交付等.到订单.

By clicking on "Buy Now" WooCommerce creates a new order in the system and what I want is to update the order created earlier during the personalization process, adding customer details, payment, delivery etc. to the order.

有可能吗?

谢谢!

推荐答案

您可以使用函数 wc_update_order() 来获取现有的订单对象.

You can use the function wc_update_order() to fetch an existing order object.

$order_id = $_GET[ 'order_id' ]
$order = wc_update_order( array ( 'order_id' => $order_id ) );

// now you got the woocommerce order object and you can execute many functions
//
$address = array(
        'first_name' => 'Fresher',
        'last_name'  => 'StAcK OvErFloW',
        'company'    => 'stackoverflow',
        'email'      => 'test@test.com',
        'phone'      => '777-777-777-777',
        'address_1'  => '31 Main Street',
        'address_2'  => '', 
        'city'       => 'Chennai',
        'state'      => 'TN',
        'postcode'   => '12345',
        'country'    => 'IN'
    );

$order->add_product( get_product( '12' ), 1 ); //(get_product with id and next is for quantity)
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();

要获取您可以在订单对象上调用的所有函数的完整列表,请在获取订单后执行以下代码

For a complete list of all the functions you can call on the order object, execute the following code after you fetch your order

var_dump( get_class_methods( $order ) );

这将列出 Woocommerce Order 对象可用的所有函数.

This will list all the functions that are available to the Woocommerce Order object.

希望这能回答您的问题

这篇关于在结帐页面中更新 woocommerce 订单以创建一个新订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆