Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Order Line Items via REST API doesn't remove existing Line Items #22177

Closed
databuzz opened this issue Dec 9, 2018 · 2 comments
Closed

Comments

@databuzz
Copy link

databuzz commented Dec 9, 2018

I'm using WooCommerce 3.5.2 and the REST API v2. I have created an Order successfully with 2 line items:

"id": 3583,
"line_items": [
{
"id": 95,
"meta_data": [],
"name": "Happy Ninja",
"price": 50,
"product_id": 37,
"quantity": 2,
"sku": "",
"subtotal": "100.00",
"subtotal_tax": "10.00",
"tax_class": "",
"taxes": [
{
"id": 1,
"subtotal": "10",
"total": "10"
}
],
"total": "100.00",
"total_tax": "10.00",
"variation_id": 0
},
{
"id": 107,
"meta_data": [],
"name": "Calligraphy Set",
"price": 89,
"product_id": 1098,
"quantity": 1,
"sku": "",
"subtotal": "89.00",
"subtotal_tax": "8.90",
"tax_class": "",
"taxes": [
{
"id": 1,
"subtotal": "8.9",
"total": "8.9"
}
],
"total": "89.00",
"total_tax": "8.90",
"variation_id": 0
}
],

I then do a PUT to /wp-json/wc/v2/orders/3583 with just one line item:

"id" : 3583,
"line_items" :
[
{
"id" : "107",
"name" : "Calligraphy Set",
"product_id" : "1098",
"quantity" : 1,
"subtotal" : "89.00",
"total" : "89.00",
"variation_id" : "0"
}
],

but it doesn't delete the 2nd line item (id 95) it simply adds an additional line item. I've tried updating the Order with no line items as well:

"id" : 3583,
"line_items" : [],

but that doesn't remove the line items. I would have thought if I didn't pass in the ID it would remove the existing line items from the Order?

@rrennick
Copy link
Contributor

rrennick commented Dec 9, 2018

To delete the second item add {"id":95,"quantity":0}.

@ThomasVeld
Copy link

This is likely because of your order status, you can't remove products from processing / completed orders. With pending orders this is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants