我正在使用woocommerce REST API为eCommerce安卓应用程序和一切工作良好,除了优惠券时,从应用程序创建新订单。
使用此接口创建订单
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没有提供计算优惠券折扣的功能,所以我不得不手动做,但不知道怎么做?那么从哪里开始呢?
甚至我得到了一个解决方案,我可以在客户端计算优惠券折扣,我做到了,但它是棘手的,因为有很多优惠券的变化,所以我的代码崩溃了一些优惠券。从前两天开始就被困住了,请帮帮我
发布于 2017-11-01 20:17:44
你可以从下面的代码开始。您必须定制order rest 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
}
https://stackoverflow.com/questions/43752725
复制相似问题