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

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

问题描述

我要做什么

我想为我的Woocommerce网站制作一个 Native Android APP (不是HTML5/Jquery移动版).我正在尝试使用 kloon/WooCommerce-REST-API-Client-图书馆.

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.

到目前为止,我设法检索了产品,优惠券,客户,订单等的清单,这些清单可以用于显示在我的Android应用中.

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

现在,我想在android应用中复制添加到购物车/结帐流程,但似乎该库未提供此类工作流程的功能.

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.

我的问题

如何在Android应用中使用REST API实现以下工作流程? (类似于网站结帐流程)

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

流量:

  1. 添加到购物车

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

  1. 退房并确认

请告诉我是否缺少任何API调用.

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.

谢谢!

推荐答案

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

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 类似于:

// 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);


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


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

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

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