WooCommerce API:创建订单和结帐 [英] WooCommerce API: create order and checkout

查看:27
本文介绍了WooCommerce API:创建订单和结帐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么

我想为我的 Woocommerce 网站制作一个原生 Android 应用(不是 HTML5/Jquery 移动版).我正在尝试使用

  1. 查看购物车并更新订单

  1. 退房和确认

如果我遗漏了任何 API 调用,请告诉我.

如果有人已经实现了这一点,请在下面发布您的资源和评论.任何示例代码/liraries/helper-classes 链接都将非常有用.

谢谢!

解决方案

如果你尝试阅读example.php并阅读lib文件夹中的所有php文件,我认为你可以实现所有这些......

example.php 有类似的东西:

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

如果你看看 class-wc-api-client-resource-orders.php,你有这个:

/*** 创建订单** 发布/订单** @从 2.0 开始* @param array $data 有效订单数据* @return array|object 你新创建的订单*/公共函数创建( $data ){$this->set_request_args( 数组('方法' =>'邮政','身体' =>$数据,) );返回 $this->do_request();}

现在你只需要测试一切.

$orderData = 数组(订单" =>大批(line_items"=>大批(大批(product_id" =>1、数量" =>1))));$client->orders->create($orderData);

<小时>

另一个建议是为什么不改用 WooCommerce REST API?它有很好的文档和示例.

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 the APIs using kloon/WooCommerce-REST-API-Client-Library.

So far I managed to retrieve the lists of products, coupons, customers, orders etc... which I could use to display in my Android app.

Now I want to replicate add to cart/checkout process in the android app, but it seems this library dosen't provide functions for such workflow.

MY QUESTION

How can I achieve the follwing workflow with REST APIs in my Android app? (Similar to the website checkout process)

Flow:

  1. Add to cart

  1. View cart and update order

  1. Check out and confirmation

Please tell me if I'm missing any API calls.

If someone already achieved this, kindly post your resources and comments bellow. Any sample-codes/liraries/helper-classes links will be greatly appriciated.

Thank you!

解决方案

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.

这篇关于WooCommerce API:创建订单和结帐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆