2017-05-03 29 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 
}