我正在以最难的方式在WooCommerce中以编程方式创建订单.我正在使用下面的代码并且正在创建订单但是我无法获得客户信息或产品订单项添加到订单中.创建的新订单仅作为Guest,没有项目,用户信息等.
问题似乎是,一旦创建了订单对象,它在尝试向订单添加数据时就会失败.
function create_vip_order() {
global $woocommerce;
$address = array(
'first_name' => '111Joe',
'last_name' => 'Conlin',
'company' => 'Speed Society',
'email' => 'joe@testing.com',
'phone' => '760-555-1212',
'address_1' => '123 Main st.',
'address_2' => '104',
'city' => 'San Diego',
'state' => 'Ca',
'postcode' => '92121',
'country' => 'US'
);
// Now we create the order
$order = wc_create_order();
// The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
$order->add_product( get_product( '275962' ), 1 ); // This is an existing SIMPLE product
$order->set_address( …Run Code Online (Sandbox Code Playgroud)