WooCommerce API: create order and checkout

旧巷老猫 提交于 2019-12-03 08:27:52

if you try to read the example.php and read all the php file in lib folder, I think you can achieve all these...

example.php has something like:

// orders
//print_r( $client->orders->get() );
//print_r( $client->orders->get( $order_id ) );
//print_r( $client->orders->update_status( $order_id, 'pending' ) );

and if you'll look at class-wc-api-client-resource-orders.php, you have this:

/**
 * Create an order
 *
 * POST /orders
 *
 * @since 2.0
 * @param array $data valid order data
 * @return array|object your newly-created order
 */
public function create( $data ) {
    $this->set_request_args( array(
        'method' => 'POST',
        'body'   => $data,
    ) );
    return $this->do_request();
}

now you'll just have to test everything.

$orderData = array(
    "order" => array(
        "line_items" => array( 
            array(
                "product_id" => 1, 
                "quantity" => 1
            ) 
        )
    )
);

$client->orders->create($orderData);

Another suggestion is why not use WooCommerce REST API instead? It has great documentation and examples.

$orderData = array( "order" => array(

/*

"set_paid"=>true

*/

"status"=>"processing",

"payment_details"=>array("method_id"=>"cod","method_title"=>"Cash on Delivery"),

"billing_address"=>array("first_name"=>"Tumusime","last_name"=>"Deus","company"=>"mcash",
"city"=>"Kampala","address_1"=>"Plot 7 Mukalazi zone","email"=>"jones@mcash.ug","phone"=>"0784529043",
),

"shipping_address"=>array("first_name"=>"Tumusime","last_name"=>"Deus","company"=>"mcash",
"city"=>"Kampala","address_1"=>"Plot 7 Mukalazi zone","email"=>"jones@mcash.ug","phone"=>"0784529043",
),
"shipping_lines"=>array(
array("id"=>5,"method_id"=>"flat_rate:1",
"method_title"=>"Flat rate","total"=>"10000.00")

),


    "line_items" => array( 
        array(
            "product_id" => 10, 
            "quantity" => 1,

        ) ,
         array(
            "product_id" => 15, 
            "quantity" => 2,

        ) 

    )
)

);

//$client->orders->create($orderData);

print_r($client->orders->create($orderData));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!