需要帮助REST API(webservivice)进行woocommerce结账

时间:2017-04-27 06:16:31

标签: php rest api woocommerce

如何使用Woocommerce REST API编写Web服务以进行结帐,包括付款方式。它是否可用于Woocommerce REST API?我是Woocommerce REST API的新手。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:2)

最后,我经过一些研究后想出来了。以下是可以帮助他人的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" => "test@gmail.com",
                                    "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" => "testsh@gmail.com",
                                    "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); `

欢呼声!!!

答案 1 :(得分:1)

您可以参考Woocommerce REST API Documentation进行Woocommerce REST API开发。

付款网关请参阅以下网址:
http://woocommerce.github.io/woocommerce-rest-api-docs/#payment-gateways

结帐时请参阅以下网址:WooCommerce API: create order and checkout

我希望这会有所帮助。