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