Get cart contents
curl --request GET \
--url {protocol}://{host}/wp-json/cocart/v2/cartimport requests
url = "{protocol}://{host}/wp-json/cocart/v2/cart"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('{protocol}://{host}/wp-json/cocart/v2/cart', 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",
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"
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")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/v2/cart")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"cart_hash": "e629fa6598d732768f7c726b4b621285",
"cart_key": "cb7a23af96a3f23af3c28a8b4b8c6d5e",
"currency": {
"currency_code": "USD",
"currency_symbol": "$",
"currency_symbol_pos": "left",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "$",
"currency_suffix": ""
},
"customer": {
"billing_address": {
"billing_first_name": "John",
"billing_last_name": "Doe",
"billing_company": "Acme Corporation",
"billing_country": "US",
"billing_address_1": "123 Main Street",
"billing_address_2": "Suite 100",
"billing_postcode": "90210",
"billing_city": "Beverly Hills",
"billing_state": "CA",
"billing_phone": "+1-555-123-4567",
"billing_email": "john.doe@example.com"
},
"shipping_address": {
"shipping_first_name": "John",
"shipping_last_name": "Doe",
"shipping_company": "Acme Corporation",
"shipping_country": "US",
"shipping_address_1": "123 Main Street",
"shipping_address_2": "Suite 100",
"shipping_postcode": "90210",
"shipping_city": "Beverly Hills",
"shipping_state": "CA"
}
},
"items": {
"d6b3e8e5a1b0c6e4f2a3b1d8c5e6f9a2": {
"item_key": "d6b3e8e5a1b0c6e4f2a3b1d8c5e6f9a2",
"id": 145,
"name": "Wireless Bluetooth Headphones",
"title": "Wireless Bluetooth Headphones",
"price": "$18.00",
"quantity": {
"value": 2,
"min_purchase": 1,
"max_purchase": -1
},
"totals": {
"subtotal": 36,
"subtotal_tax": 3.6,
"total": 36,
"tax": 3.6
},
"slug": "wireless-bluetooth-headphones",
"meta": {
"product_type": "simple",
"sku": "WBH-001",
"dimensions": {
"length": "",
"width": "",
"height": "",
"unit": "cm"
},
"weight": "0.5",
"variation": {}
},
"backorders": "no",
"cart_item_data": {},
"featured_image": "https://example-store.com/wp-content/uploads/2024/03/headphones-blue.jpg"
},
"f3a8b2c6d5e9f1a4b7c0d3e6f9a2b5c8": {
"item_key": "f3a8b2c6d5e9f1a4b7c0d3e6f9a2b5c8",
"id": 289,
"name": "Premium Cotton T-Shirt - Large, Navy Blue",
"title": "Premium Cotton T-Shirt",
"price": "$80.00",
"quantity": {
"value": 1,
"min_purchase": 1,
"max_purchase": 100
},
"totals": {
"subtotal": 80,
"subtotal_tax": 8,
"total": 80,
"tax": 8
},
"slug": "premium-cotton-tshirt",
"meta": {
"product_type": "variation",
"sku": "PCT-LG-NB",
"dimensions": {
"length": "25",
"width": "20",
"height": "2",
"unit": "cm"
},
"weight": "0.2",
"variation": {
"attribute_pa_size": "Large",
"attribute_pa_color": "Navy Blue"
}
},
"backorders": "no",
"cart_item_data": {},
"featured_image": "https://example-store.com/wp-content/uploads/2024/03/tshirt-navy.jpg"
}
},
"item_count": 3,
"items_weight": 1.5,
"coupons": [
{
"coupon": "SUMMER20",
"label": "Summer Sale 20% Off",
"saving": "$23.20",
"saving_html": "<strong>$23.20</strong>"
}
],
"needs_payment": true,
"needs_shipping": true,
"shipping": {
"total_packages": 1,
"show_package_details": true,
"has_calculated_shipping": true,
"packages": {
"default": {
"package_name": "Shipping",
"rates": {
"flat_rate_1": {
"key": "flat_rate:1",
"method_id": "flat_rate",
"instance_id": 1,
"label": "Flat Rate",
"cost": "10.00",
"html": "Flat Rate: $10.00",
"taxes": "1.00",
"chosen_method": true
},
"free_shipping_2": {
"key": "free_shipping:2",
"method_id": "free_shipping",
"instance_id": 2,
"label": "Free Shipping",
"cost": "0.00",
"html": "Free Shipping",
"taxes": "0.00",
"chosen_method": false
}
},
"package_details": "Shipped from Main Warehouse",
"index": 0,
"chosen_method": "flat_rate:1",
"formatted_destination": "Beverly Hills, CA 90210, US"
}
}
},
"fees": [
{
"name": "Gift Wrapping",
"amount": 5,
"taxable": true,
"tax_class": "standard",
"total": 5,
"tax": 0.5
}
],
"taxes": [
{
"rate_id": 1,
"label": "Sales Tax",
"compound": false,
"tax_total": "13.10",
"shipping_tax_total": "1.00"
}
],
"totals": {
"subtotal": "116.00",
"subtotal_tax": "11.60",
"shipping_total": "10.00",
"shipping_tax": "1.00",
"shipping_taxes": [
1
],
"discount_total": "23.20",
"discount_tax": "0.00",
"cart_contents_total": "92.80",
"cart_contents_tax": "11.10",
"cart_contents_taxes": [
11.1
],
"fee_total": "5.00",
"fee_tax": "0.50",
"fee_taxes": [
0.5
],
"total": "119.40",
"total_tax": "13.60"
},
"removed_items": [],
"cross_sells": [
{
"id": 312,
"product_name": "Wireless Charging Pad",
"product_title": "Wireless Charging Pad",
"price": "$29.99",
"regular_price": "$39.99",
"sale_price": "$29.99",
"product_image": "https://example-store.com/wp-content/uploads/2024/03/charging-pad.jpg"
},
{
"id": 445,
"product_name": "Phone Case - Universal",
"product_title": "Phone Case - Universal",
"price": "$15.99",
"regular_price": "$15.99",
"sale_price": "",
"product_image": "https://example-store.com/wp-content/uploads/2024/03/phone-case.jpg"
}
],
"extensions": {}
}{
"code": "cocart_invalid_parameter",
"message": "Invalid cart_key parameter.",
"data": {
"status": 400
}
}{
"code": "cocart_cart_not_found",
"message": "Cart not found.",
"data": {
"status": 404
}
}Get cart
Get the full cart including all items, totals, and customer information.
GET
/
cart
Get cart contents
curl --request GET \
--url {protocol}://{host}/wp-json/cocart/v2/cartimport requests
url = "{protocol}://{host}/wp-json/cocart/v2/cart"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('{protocol}://{host}/wp-json/cocart/v2/cart', 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",
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"
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")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/v2/cart")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"cart_hash": "e629fa6598d732768f7c726b4b621285",
"cart_key": "cb7a23af96a3f23af3c28a8b4b8c6d5e",
"currency": {
"currency_code": "USD",
"currency_symbol": "$",
"currency_symbol_pos": "left",
"currency_minor_unit": 2,
"currency_decimal_separator": ".",
"currency_thousand_separator": ",",
"currency_prefix": "$",
"currency_suffix": ""
},
"customer": {
"billing_address": {
"billing_first_name": "John",
"billing_last_name": "Doe",
"billing_company": "Acme Corporation",
"billing_country": "US",
"billing_address_1": "123 Main Street",
"billing_address_2": "Suite 100",
"billing_postcode": "90210",
"billing_city": "Beverly Hills",
"billing_state": "CA",
"billing_phone": "+1-555-123-4567",
"billing_email": "john.doe@example.com"
},
"shipping_address": {
"shipping_first_name": "John",
"shipping_last_name": "Doe",
"shipping_company": "Acme Corporation",
"shipping_country": "US",
"shipping_address_1": "123 Main Street",
"shipping_address_2": "Suite 100",
"shipping_postcode": "90210",
"shipping_city": "Beverly Hills",
"shipping_state": "CA"
}
},
"items": {
"d6b3e8e5a1b0c6e4f2a3b1d8c5e6f9a2": {
"item_key": "d6b3e8e5a1b0c6e4f2a3b1d8c5e6f9a2",
"id": 145,
"name": "Wireless Bluetooth Headphones",
"title": "Wireless Bluetooth Headphones",
"price": "$18.00",
"quantity": {
"value": 2,
"min_purchase": 1,
"max_purchase": -1
},
"totals": {
"subtotal": 36,
"subtotal_tax": 3.6,
"total": 36,
"tax": 3.6
},
"slug": "wireless-bluetooth-headphones",
"meta": {
"product_type": "simple",
"sku": "WBH-001",
"dimensions": {
"length": "",
"width": "",
"height": "",
"unit": "cm"
},
"weight": "0.5",
"variation": {}
},
"backorders": "no",
"cart_item_data": {},
"featured_image": "https://example-store.com/wp-content/uploads/2024/03/headphones-blue.jpg"
},
"f3a8b2c6d5e9f1a4b7c0d3e6f9a2b5c8": {
"item_key": "f3a8b2c6d5e9f1a4b7c0d3e6f9a2b5c8",
"id": 289,
"name": "Premium Cotton T-Shirt - Large, Navy Blue",
"title": "Premium Cotton T-Shirt",
"price": "$80.00",
"quantity": {
"value": 1,
"min_purchase": 1,
"max_purchase": 100
},
"totals": {
"subtotal": 80,
"subtotal_tax": 8,
"total": 80,
"tax": 8
},
"slug": "premium-cotton-tshirt",
"meta": {
"product_type": "variation",
"sku": "PCT-LG-NB",
"dimensions": {
"length": "25",
"width": "20",
"height": "2",
"unit": "cm"
},
"weight": "0.2",
"variation": {
"attribute_pa_size": "Large",
"attribute_pa_color": "Navy Blue"
}
},
"backorders": "no",
"cart_item_data": {},
"featured_image": "https://example-store.com/wp-content/uploads/2024/03/tshirt-navy.jpg"
}
},
"item_count": 3,
"items_weight": 1.5,
"coupons": [
{
"coupon": "SUMMER20",
"label": "Summer Sale 20% Off",
"saving": "$23.20",
"saving_html": "<strong>$23.20</strong>"
}
],
"needs_payment": true,
"needs_shipping": true,
"shipping": {
"total_packages": 1,
"show_package_details": true,
"has_calculated_shipping": true,
"packages": {
"default": {
"package_name": "Shipping",
"rates": {
"flat_rate_1": {
"key": "flat_rate:1",
"method_id": "flat_rate",
"instance_id": 1,
"label": "Flat Rate",
"cost": "10.00",
"html": "Flat Rate: $10.00",
"taxes": "1.00",
"chosen_method": true
},
"free_shipping_2": {
"key": "free_shipping:2",
"method_id": "free_shipping",
"instance_id": 2,
"label": "Free Shipping",
"cost": "0.00",
"html": "Free Shipping",
"taxes": "0.00",
"chosen_method": false
}
},
"package_details": "Shipped from Main Warehouse",
"index": 0,
"chosen_method": "flat_rate:1",
"formatted_destination": "Beverly Hills, CA 90210, US"
}
}
},
"fees": [
{
"name": "Gift Wrapping",
"amount": 5,
"taxable": true,
"tax_class": "standard",
"total": 5,
"tax": 0.5
}
],
"taxes": [
{
"rate_id": 1,
"label": "Sales Tax",
"compound": false,
"tax_total": "13.10",
"shipping_tax_total": "1.00"
}
],
"totals": {
"subtotal": "116.00",
"subtotal_tax": "11.60",
"shipping_total": "10.00",
"shipping_tax": "1.00",
"shipping_taxes": [
1
],
"discount_total": "23.20",
"discount_tax": "0.00",
"cart_contents_total": "92.80",
"cart_contents_tax": "11.10",
"cart_contents_taxes": [
11.1
],
"fee_total": "5.00",
"fee_tax": "0.50",
"fee_taxes": [
0.5
],
"total": "119.40",
"total_tax": "13.60"
},
"removed_items": [],
"cross_sells": [
{
"id": 312,
"product_name": "Wireless Charging Pad",
"product_title": "Wireless Charging Pad",
"price": "$29.99",
"regular_price": "$39.99",
"sale_price": "$29.99",
"product_image": "https://example-store.com/wp-content/uploads/2024/03/charging-pad.jpg"
},
{
"id": 445,
"product_name": "Phone Case - Universal",
"product_title": "Phone Case - Universal",
"price": "$15.99",
"regular_price": "$15.99",
"sale_price": "",
"product_image": "https://example-store.com/wp-content/uploads/2024/03/phone-case.jpg"
}
],
"extensions": {}
}{
"code": "cocart_invalid_parameter",
"message": "Invalid cart_key parameter.",
"data": {
"status": 400
}
}{
"code": "cocart_cart_not_found",
"message": "Cart not found.",
"data": {
"status": 404
}
}Query Parameters
Response
Cart retrieved successfully.
Complete cart object with enhanced v2 structure.