天天看點

php自動更新新訂單,php-在結帳頁面中更新woocommerce訂單,而不是建立一個新的

我正在建立一個執行以下操作的Wordpress和WooCommerce插件:

>匿名使用者在頁面上自定義産品

>在過程中的php腳本中,它在資料庫中建立一個訂單

>使用者轉到要求客戶資料,交貨等的結帳頁面.

通過單擊“立即購買”,WooCommerce在系統中建立了一個新訂單,我要更新的是在個性化過程中先前建立的訂單,将客戶詳細資訊,付款,交貨等添加到訂單中.

可能嗎?

謝謝!

解決方法:

您可以使用函數wc_update_order()來擷取現有的訂單對象.

$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' => '[email protected]',

'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();

有關可以在訂單對象上調用的所有功能的完整清單,請在擷取訂單後執行以下代碼

var_dump( get_class_methods( $order ) );

這将列出Woocommerce Order對象可用的所有功能.

希望這能回答您的問題

标簽:php,wordpress,woocommerce,wordpress-plugin

來源: https://codeday.me/bug/20191009/1880791.html