2017-04-27 72 views

回答

1

您可以參考Woocommerce REST API Documentation進行Woocommerce REST API開發。

支付網關參考以下網址:
http://woocommerce.github.io/woocommerce-rest-api-docs/#payment-gateways

結帳請參閱以下網址:WooCommerce API: create order and checkout

我希望這有助於。

+0

謝謝LuffY ,.你能否給我提供一些關於結帳的代碼。 –

+0

@SatyendraPrakash,你有答案嗎?如果是,請接受答案:) – LuFFy

+0

不完整@LuFFy,訂單正在創建,但我應該如何傳遞其他信息,如結算和送貨地址,因爲運費和帳單地址是空的 –

1

最後,我經過一番研究後發現它。以下是可以幫助他人的woocommerce checkout webservice的工作代碼 -

/*** Just Copy & Paste and change your varriables **/ 

    //do your initial stuff 
    header('Content-type: application/json'); 
    $json_file=file_get_contents('php://input'); 
    $jsonvalue= json_decode($json_file,true); 

    $user_id = $jsonvalue['user_id']; 
    $product_id = $jsonvalue['product_id']; 
    $quantity = $jsonvalue['quantity'];  

//start order data 
$orderData = array( 
    "order" => array(
    'payment_method' => 'paypal', 
    'payment_method_title' => 'Paypal', 
    'set_paid' => true, 
    "billing_address" => array(
            "first_name" => "bfname", 
            "last_name" => "blname", 
            "company" => "testcompanybilling", 
            "address_1" => "sec8", 
            "address_2" => "e32", 
            "city" => "noida", 
            "state" => "Noida", 
            "postcode" => "99999", 
            "country" => "IN", 
            "email" => "[email protected]", 
            "phone" => "888899999999" 

          ), 
     "shipping_address" => array(
            "first_name" => "sfname", 
            "last_name" => "slname", 
            "company" => "testcompanyshipping", 
            "address_1" => "shakkarpur", 
            "address_2" => "laxminigar", 
            "city" => "New Delhi", 
            "state" => "Delhi", 
            "postcode" => "110092", 
            "country" => "IN", 
            "email" => "[email protected]", 
            "phone" => "11009999" 
          ), 
    "customer_id" => $user_id, 
    "line_items" => array( 
     array(
      "product_id" => $product_id, 
      "quantity" => $quantity 
     ) 
    ) 
    ) 
); 

//Create order usind order data 
$data = $client->orders->create($orderData); 
//echo '<pre>'; 
//print_r($data); 
$result['success']='true'; 
$result['error']="0"; 
$result['msg']='Your order has been successfully placed.'; 
$result['data']=$data; 

echo json_encode($result); ` 

乾杯!