Count cart items
curl --request GET \
--url {protocol}://{host}/wp-json/cocart/v2/cart/items/countimport requests
url = "{protocol}://{host}/wp-json/cocart/v2/cart/items/count"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('{protocol}://{host}/wp-json/cocart/v2/cart/items/count', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "{protocol}://{host}/wp-json/cocart/v2/cart/items/count",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "{protocol}://{host}/wp-json/cocart/v2/cart/items/count"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("{protocol}://{host}/wp-json/cocart/v2/cart/items/count")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/v2/cart/items/count")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body5{
"code": "cocart_invalid_parameter",
"message": "Invalid return format parameter.",
"data": {
"status": 400
}
}GET
/
cart
/
items
/
count
Error
A valid request URL is required to generate request examples5{
"code": "cocart_invalid_parameter",
"message": "Invalid return format parameter.",
"data": {
"status": 400
}
}This endpoint will be deprecated in the future. Recommend getting the items count from the main cart endpoint.
Query Parameters
Return count as a string or array format.
Available options:
numeric Response
Cart item count retrieved successfully.
Number of items in the cart.
Example:
5
Was this page helpful?
⌘I