2017-05-03 114 views
2

我使用电子商务的Android应用woocommerce REST API和一切除了优惠券从应用程序创建新订单时,工作好。如何创建从Android应用程序的新订单时,使用Woocommerce REST API申请优惠券?

使用该API来创建顺序

https://my-domain.com/wp-json/wc/v2/orders 

和传递一些JSON数据包括

"coupon_lines" => [ 
    "id" => 111, 
    "code" => "coupon code", 
    "discount" => "10.0", 
    "discount_tax" => "0" 
] 

通过这种方式优惠券将被应用到订单,但量不从总减小。谁能帮帮我吗?我是woocommerce新手。

我搜索的结果,并得到了woocommerce REST API未提供的功能来计算优惠券折扣,所以我必须做手工,但不知道该怎么办呢?并从哪里开始?

即使我得到了一个解决方案,我可以在客户端计算优惠券折扣,但我做到了,但它很棘手,因为优惠券有很多变体,所以我的代码打破了一些优惠券。因为最后两天完全停留在此请大家帮我

+0

与溶液中的任何运气? – Aroniez

+0

对不起!不幸的是,我也没有得到任何解决方案。因为woocommerce api不提供任何优惠券的自动计算,所以您必须用自己的方式来完成。 – DD77

回答

0

您可以用代码以下方式启动。 用户还可自定义的顺序其余API,你可以让你的自定义代码的计算优惠券金额传递给API自定义响应的响应。

add_filter('woocommerce_rest_prepare_shop_order_object', 'custom_change_shop_order_response', 10, 3); 
function custom_change_shop_order_response($response, $object, $request) { 
    //here you can get the three parameters. 
// In the $response you can get the default response of the orders. 
// In the $request you can get the request.here you can get a coupon code 
// do your magic code here 
} 
相关问题