0

I am trying to create an order on my WooCommerce store from my mobile application using the REST API v2. The order is created successfully but I can't find any solution to the following issues.

  1. I send a coupon_lines array within the order object and when the order is viewed on the admin panel, it shows the coupon there but the order total is not affected at all.
  2. Then I decided to calculate the total and discounts based on the applied coupon manually. I tried to set discount_total within the order object equal to the amount which is the value of the coupon. I also update the total manually as well. But again, all the values that I pass are ignored and the order total is equal to the sum of the prices of all line items (ignoring discount_total).

Here is a sample JSON object that is sent to the API from my app.

The order total should should be 5000, but it is 10000 in the WordPress admin panel because the Coupon Code for 5000 has no effect. Also, the <code>discount_total</code> has no effect. It is 0 in the response <code>order</code> object.

What other options do I have to set an order total and discount manually? Any suggestions are welcome.

1 Answer 1

0

In your coupon_lines array, each item in the array needs 2 properties: code (the coupon code itself) and amount, which is either a flat fee (eg 50.00 off) or a discount (eg 10% off). Your structure ends up looking like:

"coupon_lines": [
    {
        "code": "MYCODE1",
        "amount": "10.00"
    },
    {
        "code": "MYCODE2",
        "amount": "25.00"
    }
]

If you're already doing this - consider posting an example request here.

7
  • Hi. I looked at the docs and thus have the field discount instead of amount. Also updated the code with image of the JSON request object. Commented Aug 1, 2018 at 14:12
  • The REST API docs say it should be amount. Commented Aug 1, 2018 at 14:13
  • When I tried with amount instead of discount, this is what I get (i.imgur.com/45O9cFz.png) I think you referred to old docs. Here (woocommerce.github.io/woocommerce-rest-api-docs/…) are the docs for REST API v2. Commented Aug 1, 2018 at 14:31
  • Sorry, you're right. It looks like you can't use this as an actual feature until WC API v3, which is in development. The fields you've tried to set (such as total, discount_total etc) are all read-only so they will not effect anything. You might have to end up going through each line item and removing values from the total field (not subtotal!) Commented Aug 1, 2018 at 14:49
  • 2
    So for a fixed discount, I will have to divide that discount proportionally amongst all products. And for a percentage discount, I can simply reduce the price by that percentage. Right? But this is such a dirty way. Commented Aug 1, 2018 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.