Kings Samuel
Kings Samuel

Reputation: 185

Why Woocommerce API GET request returns an empty cart items list

I have a problem with the API_TEST of my woocommerce site. I am currently building an e-commerce app that uses woocommerce as its backend. I edited a webhook file(class-wc-rest-webhooks-controller.php.) in my Cpanel to enable the "add to cart" functionality. (See file code here: https://github.com/Kings-Samuel/Kings-Samuel/blob/main/class-wc-rest-webhooks-controller.php.php )

Now, to do an HTTP test on PostMan, the POST request works very fine. The GET request works pretty well too but has one problem.

If I update the cart from my woocommerce website, it will return the cart items properly. But if I try to GET the cart items when I use the POST request to update the cart, it will show me a 200 (Success) but refuses to show me the cart items. It just returns an empty cart list.

So, in essence, the GET request works only if the cart was updated from the website. It doesn't work when the cart is updated from the post request or from the app.

Please what could be the problem? Below is the HHTP and JSON detail of what is returned...

HTTP/1.1 200 OK
keep-alive: timeout=5, max=100
content-type: application/json; charset=UTF-8
x-robots-tag: noindex
link: <https://jumbocheap.com/wp-json/>; rel="https://api.w.org/"
x-content-type-options: nosniff
access-control-expose-headers: X-WP-Total, X-WP-TotalPages, Link
access-control-allow-headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
allow: GET
vary: Origin,Accept-Encoding
cache-control: public, max-age=0
expires: Sat, 27 Nov 2021 19:00:50 GMT
content-length: 25
date: Sat, 27 Nov 2021 19:00:50 GMT
server: LiteSpeed
x-turbo-charged-by: LiteSpeed
connection: close

{
  "status": true,
  "data": []
}

Upvotes: 0

Views: 420

Answers (1)

Kings Samuel
Kings Samuel

Reputation: 185

I've got the solution to this. It turned out that I once used the lower case to declare a variable instead of a lower camel case in the class-wc-rest-webhooks-controller.php file.

Now, my cart works just fine

Upvotes: 1

Related Questions