WooCommerce API: create order and checkout

后端 未结 2 1584
暗喜
暗喜 2021-02-06 15:46

WHAT AM I TRYING TO DO

I want to make a Native Android APP (Not HTML5/Jquery mobile) for my Woocommerce website. I am trying to setup t

2条回答
  •  忘了有多久
    2021-02-06 15:54

    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.

提交回复
热议问题