• In the documentation you have provided how to update an order using the API

    curl -X PUT https://example.com/wp-json/wc/v1/orders/154 \
    -u consumer_key:consumer_secret \
    -H “Content-Type: application/json” \
    -d ‘{
    “status”: “completed”
    }’

    However, you have only provided how to update status. I was able to update the payment details and order meta as well. But I am not able to edit existing items in the order or update the items such as its quantity or price in the order. How can I do this? Thanks.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Look at the order props that can be set in the list here https://woothemes.github.io/woocommerce-rest-api-docs/#order-properties

    As long as you use those keys and valid values it will update anything listed.

    Thread Starter fid

    (@fid)

    Almost all of them are read-only. What if I wanted to remove a line item from a pending order? I tried making the quantity 0 but it did not work.

    {
      "errors": [
        {
          "code": "woocommerce_api_invalid_product_quantity",
          "message": "Product quantity must be a positive float"
        }
      ]
    }
    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    @fid by default we never offered any method to remove order item lines.
    I logged this feature in our roadmap, so we can include into the next version: https://trello.com/c/8ZTYAzH8/93-rest-api-allow-remove-order-line-items
    For now maybe is better to delete (or cancel) and create the order again.

    Thread Starter fid

    (@fid)

    Thanks so much guys.

    I think this is a super important feature for api driven frontends especially because at the moment the only solution to have all the details (total taxes, price(s), shipping fee etc) resolved with 1 call before the actual checkout is to create a pending order, but we need to allow the user to go back and remove some item from his cart before paying.

    btw: I’d also introduce a cart endpoint but is nor urgent neither essential, it would be just a way to have everything tracked on the backend and make profit of existent plugins for abandoned carts.

    Thread Starter fid

    (@fid)

    I see you have added this feature. What is the solution for this then? How to remove a line item?

    @fid yo need to update the order and give quantity 0 for item you want to remove.
    I suggest you to persist somehow the order or you need to get it first every time you want to update because each line item gets an id you need to put into the new json when you update or you’ll add a new line item instead of update the existing one (product id is not enough).

    I believe we have the latest version of WordPress, but I cannot update line item quantity with “0”. Still get “Product quantity must be a positive float” error.

    My JSON looks like:
    {“line_items”:[{“id”:”54″,”sku”:”MYPART”,”quantity”:”0″,”price”:”5.00″},{“sku”:”MYPART”,”quantity”:”12″,”price”:”10.00″}]}

    So, I am zeroing out the original line and creating a new one.

    What version of WP do I need?

    Thanks,
    Ken

    Thread Starter fid

    (@fid)

    @claudiosanches
    It says this is done on your trello board but I still get this error when trying to remove a line item via the API.

    {
      "errors": [
        {
          "code": "woocommerce_api_invalid_product_quantity",
          "message": "Product quantity must be a positive float"
        }
      ]
    }
    knhark59

    (@knhark59)

    I am setting the quantity to .0001. This seems to get past the “must be a positive float” error and the order appears to be updated with 0 qty. Maybe it’s rounding, but it appears to be zero and the other values also get zeroed out.

    I hate trying to “trick” the system this way, but it appears to work. Cancelling and recreating the order is not a good option for us.

    Not sure if it will create some other problem (divide by zero or something) down the line, but it appears to be okay now.

    @claudiosanches: Any thoughts?

    Ken

    enricodeleo

    (@enricodeleo)

    @knhark59 very clever, although it was solved (see my pull request https://github.com/woocommerce/woocommerce/pull/11533)

    knhark59

    (@knhark59)

    @enricodeleo

    I have the most recent versions of WooCommerce and the API, but I still get the “Product quantity must be a positive float” error.

    I can set the quantity to zero on the Edit Order page in the gui, but not via the API.

    I looked at the pull request, and found the class-wc-orders-controller.php file on my system. I changed the line as indicated in your pull request (the change was not in my version). It now deletes the line when I set the quantity to zero.

    I just installed WordPress, WooCommerce and the API plugin just a week ago, so I think I’ve got the latest versions.

    Ken

    Thread Starter fid

    (@fid)

    @knhark59 Its still not working on the latest version of WC.

    {
      "errors": [
        {
          "code": "woocommerce_api_invalid_product_quantity",
          "message": "Product quantity must be a positive float"
        }
      ]
    }

    Yeah, I’m still having this same issue. Setting the product_id to null seemed to work though.

    https://github.com/woocommerce/woocommerce/pull/11533

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Update order via Rest API’ is closed to new replies.