Skip to content
Advertisement

Unable to delete product category via WooCommerce REST API

I’m using WooCommerce REST API v3, to perform basic CRUD operations on products and categories, remotely – WP is hosted on one server (e.g. example.com), and the logic doing the CRUD is on another server (e.g. mysite.com).

While I am able to list, create and update product categories, I can not delete them. None of the categories I want to delete have subcategories, and there are no products attached to them.

This is my code:

JavaScript

cURL returns what I’d expect, and what the documentation says, the status code is 200, but when I look at the product categories in my WordPress site, the category is still there.

I have also tried changing the request type to POST (the server doesn’t support DELETE as a custom request type), like this:

JavaScript

My guess is that the API doesn’t know that I’m trying to delete something, and that’s why it’s just returning the info on the category (force=true not being enough for deleting the category).

Is there any other parameter which I can pass to WC API, in order to make it delete the category I want it to delete? If so, how?

Advertisement

Answer

I’ve managed to solve it by adding an additional parameter – _method=DELETE – thanks to instructions on how to do an override found here.

Working code:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement