【发布时间】:2019-06-03 17:17:21
【问题描述】:
我正在尝试将手动订单添加到 woocommerce。网上商店是我拥有股票价值的地方。我也有店。当客户在商店购买时,我必须添加订单。当我想通过 Orders->Add order 添加它时,它不能正常工作,因为我需要添加税值手册(自动,为什么?)。 我想要隐藏页面,添加订单。
我见过Programmatically creating new order in Woocommerce
这是我尝试过的: 我在主文件夹中有 order.php 文件:
<?php
/*
* Create order dynamically
*/
require(dirname(__FILE__) . '/wp-load.php');
echo 'ok?';
function create_vip_order() {
global $woocommerce;
$address = array(
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'test@gmail.com',
'phone' => '123456789',
'address_1' => '123 Main st.',
'city' => 'San Diego',
'state' => 'Ca',
'postcode' => '92121',
);
// 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( '376' ), 1 ); // This is an existing SIMPLE product
$order->set_address( $address, 'billing' );
//
$order->calculate_totals();
$order->update_status("Completed", 'Imported order', TRUE);
}
add_action( 'init', 'create_vip_order' );
【问题讨论】:
-
您遇到的错误是什么,请在此处明确您的问题。,
-
哦,脚本没有出错,但没有下新订单。
-
是
create_vip_order函数调用了吗? -
不明白你的问题。
-
哦,我明白了。我从来没有调用过那个函数……真丢脸。
标签: php wordpress woocommerce orders