NAV Navbar
cURL jQuery PHP WP API

CoCart Pro

CoCart Pro completes the API package with more control to the cart.

This section of the documentation is for CoCart Pro only! You can access the core of CoCart documentation here.

Requirements

To use the latest version of the CoCart Pro you must be using the same requirements as CoCart including:

Error Responses

You might encounter an error when using CoCart Pro. These error responses explain what might have happened.

Error Status Error Response
cocart_pro_coupons_not_enabled Coupons are not enabled for this store!
cocart_pro_coupon_required Coupon is required in order to apply!
cocart_pro_coupons_expired The following coupons have expired or no longer valid: %s %s are the coupons expired
cocart_pro_coupon_failed_to_apply Coupon failed to apply to cart.
cocart_pro_coupon_failed_to_remove Coupon failed to remove from cart.
cocart_pro_add_fee_missing_name The name of the fee is missing!
cocart_pro_add_fee_missing_amount The amount of the fee is missing!
cocart_pro_cannot_add_fee There is nothing in the cart so no fee can be added.
cocart_pro_fee_already_exists Fee has already been added.
cocart_pro_removing_fees_failed Cart fees failed to remove.
cocart_pro_no_payment_gateways Please fill in your details above to see available payment methods.
cocart_pro_set_payment_method_failed The gateway ID is required to set a payment method.
cocart_pro_payment_method_incorrect The gateway ID is either incorrect or does not exist.
cocart_pro_shipping_not_enabled Shipping has not been enabled for this store!
cocart_pro_shipping_not_needed Cart does not contain an item that requires shipping.
cocart_pro_no_recurring_cart_key The recurring cart key does not exists.
cocart_pro_shipping_not_calculated Customer has not calculated shipping.
cocart_pro_set_shipping_method_failed Both the method ID and instance ID are required to set a shipping method.
cocart_pro_shipping_method_incorrect The shipping method is either incorrect or does not exist.
cocart_pro_invalid_postcode Please enter a valid postcode / ZIP.
cocart_pro_no_shipping_methods There are no shipping methods available!

Calculate

The following allow you to calculate fees, shipping and the totals of the cart.

Calculate Cart Totals

This API helps you calculate the cart totals. You can also request to return the totals once calculated to reduce API requests and use the Get Cart Totals properties.

Properties

Attribute Type Description
return bool Set as true to return the totals once calculated. optional

HTTP request

POST
/wp-json/cocart/v1/calculate
curl -X POST https://example.com/wp-json/cocart/v1/calculate \
    -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/calculate",
  "method": "POST"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/calculate",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_post( 'https://example.com/wp-json/cocart/v1/calculate' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"Cart totals have been calculated."

Calculate Fees

This API helps you calculate the fees.

Properties

Attribute Type Description
set_session bool Sets the cart fees in session once calculated. optional, used mainly for internal use.
return bool Returns the cart fees once calculated.

HTTP request

POST
/wp-json/cocart/v1/calculate/fees
curl -X POST https://example.com/wp-json/cocart/v1/calculate/fees \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/calculate/fees",
  "method": "POST"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/calculate/fees",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_post( 'https://example.com/wp-json/cocart/v1/calculate/fees' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"Cart fees have been calculated."

Calculate Shipping

This API helps you calculate the shipping costs and get the available methods. You can also request to return the shipping methods once calculated to reduce API requests.

Properties

Attribute Type Description
country string Set the country of the shipping location. required
state string Setting the state is optional but maybe required under some circumstances. optional
city string Set the city to specify location in country. optional
postcode string Enter postcode / ZIP to narrow down location for more accurate shipping cost. optional
return_methods bool Set as true to return the shipping methods once calculated. optional

HTTP request

POST
/wp-json/cocart/v1/calculate/shipping
curl -X POST https://example.com/wp-json/cocart/v1/calculate/shipping \
  -H "Content-Type: application/json"
  -d '{
    "country": "GB"
  }'
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/calculate/shipping",
  "method": "POST",
  "data": {
    "country" : "GB",
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

$args = array(
  'country' => 'GB',
);

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/calculate/shipping",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $args,
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$args = array(
  'country' => 'GB',
);

$response = wp_remote_post( 'https://example.com/wp-json/cocart/v1/calculate/shipping', $args );
$body = wp_remote_retrieve_body( $response );

JSON response example

"Shipping costs updated."

Coupons

This API helps you get applied coupons, add coupons to cart, remove coupons from cart and check coupons for validation.

Coupon Properties

Attribute Type Description
coupon string Coupon code is required in order to apply it to or remove it from cart. required

Applied Coupons

Returns all applied coupons to the cart.

HTTP request

GET
/wp-json/cocart/v1/coupon
curl -X GET https://example.com/wp-json/cocart/v1/coupon \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/coupon",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/coupon",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/coupon' );
$body = wp_remote_retrieve_body( $response );

JSON response example for returning already applied coupons.

{
  "summer20"
}

Apply Coupon

Apply a coupon to the cart.

HTTP request

POST
/wp-json/cocart/v1/coupon
curl -X POST https://example.com/wp-json/cocart/v1/coupon \
  -H "Content-Type: application/json" \
  -d '{
    "coupon": "summer20"
  }'
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/coupon",
  "method": "POST",
  "data": {
    "coupon": "summer20"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

$args = array(
  'coupon' => 'summer20'
);

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/coupon",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $args,
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$args = array(
  'coupon' => 'summer20'
);
$response = wp_remote_post( 'https://example.com/wp-json/cocart/v1/coupon', $args );
$body = wp_remote_retrieve_body( $response );

JSON response example.

{
    "message": "Coupon was successfully added to cart.",
    "coupon": "summer20",
    "response": true
}

Remove Coupon

Remove a coupon from the cart.

HTTP request

DELETE
/wp-json/cocart/v1/coupon
curl -X DELETE https://example.com/wp-json/cocart/v1/coupon \
  -H "Content-Type: application/json" \
  -d '{
    "coupon": "summer20"
  }'
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/coupon",
  "method": "DELETE",
  "data": {
    "coupon": "summer20"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

$args = array(
  'coupon' => 'summer20'
);

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/coupon",
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_POSTFIELDS => $args,
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$args = array(
  'method' => 'DELETE',
  'coupon' => 'summer20'
);
$response = wp_remote_request( 'https://example.com/wp-json/cocart/v1/coupon', $args );
$body = wp_remote_retrieve_body( $response );

JSON response example.

{
    "message": "Coupon was successfully removed from cart.",
    "coupon": "summer20",
    "response": true
}

Check Coupons

Checks applied coupons to see if they are still valid or if they have expired or no longer valid.

HTTP request

GET
/wp-json/cocart/v1/check-coupons
curl -X GET https://example.com/wp-json/cocart/v1/check-coupons \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/check-coupons",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/check-coupons",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/check-coupons' );
$body = wp_remote_retrieve_body( $response );

JSON response example.

"Coupons applied are still valid!"

Cross Sells

This API helps you get the cross sells. It returns not just the product ID's but the product name, price, regular price and sale price.

Cross Sell Properties

Attribute Type Description
thumb bool Set as true to return the product thumbnail for each item.

HTTP request

GET
/wp-json/cocart/v1/cross-sells
curl -X GET https://example.com/wp-json/cocart/v1/cross-sells \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/cross-sells",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/cross-sells",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/cross-sells' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
    "29": {
        "id": 29,
        "product_name": "Hoodie with Logo",
        "product_title": "Hoodie with Logo",
        "price": "£45.00",
        "regular_price": "£45.00",
        "sale_price": "£0.00"
    },
    "30": {
        "id": 30,
        "product_name": "Hoodie with Pocket",
        "product_title": "Hoodie with Pocket",
        "price": "£35.00",
        "regular_price": "£45.00",
        "sale_price": "£35.00"
    },
    "31": {
        "id": 31,
        "product_name": "Hoodie with Zipper",
        "product_title": "Hoodie with Zipper",
        "price": "£45.00",
        "regular_price": "£45.00",
        "sale_price": "£0.00"
    }
}```

Cart Owner

This API helps you get the cart owner's details of the customer.

HTTP request

GET
/wp-json/cocart/v1/customer
curl -X GET https://example.com/wp-json/cocart/v1/customer \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/customer",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/customer",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/customer' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
  "user": {
    "ID": 1,
    "first_name": "John",
    "last_name": "Doe"
  },
  "billing": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "Company Name LTD",
    "email": "3naxbgjjttb@thrubay.com",
    "phone": "070 4502 9873",
    "country": "GB",
    "state": "",
    "postcode": "L23 6ST",
    "city": "LITTLE CROSBY",
    "address": "48 Victoria Road",
    "address_1": "48 Victoria Road",
    "address_2": ""
  },
  "shipping": {
    "first_name": "John",
    "last_name": "Doe",
    "company": "Company Name LTD",
    "country": "GB",
    "state": "",
    "postcode": "L23 6ST",
    "city": "LITTLE CROSBY",
    "address": "48 Victoria Road",
    "address_1": "48 Victoria Road",
    "address_2": ""
  },
  "has_calculated_shipping": true,
  "is_vat_exempt": "no"
}

Fees

This API helps you add a fee to the cart, get all fees added, and remove all fees.

Get Fees

Returns all applied fees to the cart.

HTTP request

GET
/wp-json/cocart/v1/fees
curl -X GET https://example.com/wp-json/cocart/v1/fees \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/fees",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/fees",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/fees' );
$body = wp_remote_retrieve_body( $response );

JSON response example for returning already applied fees.

{
  "cocart-extra-package-protection":{
    "id": "cocart-extra-package-protection",
    "name": "Extra Package Protection",
    "amount": "40",
    "taxable": false,
    "tax_class": "",
    "total": 4000
  }
}

Add a Fee

Apply a fee to the cart.

Properties

Attribute Type Description
name string Name of the fee. required
amount string Amount for the fee. required
taxable bool Determins if the fee is taxable. optional
tax_class string The tax class the fee applies to. optional

HTTP request

POST
/wp-json/cocart/v1/fees
curl -X POST https://example.com/wp-json/cocart/v1/fees \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Extra Package Protection",
    "amount": "40"
  }'
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/fees",
  "method": "POST",
  "data": {
    "name": "Extra Package Protection",
    "amount": "40"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

$args = array(
  "name"   => "Extra Package Protection",
  "amount" => "40"
);

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/fees",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $args,
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$args = array(
  "name"   => "Extra Package Protection",
  "amount" => "40"
);
$response = wp_remote_post( 'https://example.com/wp-json/cocart/v1/fees', $args );
$body = wp_remote_retrieve_body( $response );

JSON response example.

{
    "Fee \"Extra Package Protection\" for £40.00 has been added."
}

Remove Fees

Remove all fees from the cart.

HTTP request

DELETE
/wp-json/cocart/v1/fees
curl -X DELETE https://example.com/wp-json/cocart/v1/fees \
  -H "Content-Type: application/json" \
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/fees",
  "method": "DELETE"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/fees",
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$args = array(
  'method' => 'DELETE'
);
$response = wp_remote_request( 'https://example.com/wp-json/cocart/v1/fees', $args );
$body = wp_remote_retrieve_body( $response );

JSON response example.

{
    "All cart fees have been removed."
}

Payment Methods

This API helps you get the payment methods available.

HTTP request

GET
/wp-json/cocart/v1/payment-methods
curl -X GET https://example.com/wp-json/cocart/v1/payment-methods \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/payment-methods",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/payment-methods",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/payment-methods' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
    "bacs": {
        "id": "bacs",
        "method_title": "Direct bank transfer",
        "title": "Direct bank transfer",
        "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.",
        "icon": "",
        "icon_urls": "",
        "has_fields": false,
        "countries": null,
        "availability": null,
        "supports": [
            "products"
        ],
        "order_button_text": null,
        "chosen_gateway": false
    },
    "cheque": {
        "id": "cheque",
        "method_title": "Check payments",
        "title": "Check payments",
        "description": "Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.",
        "icon": "",
        "icon_urls": "",
        "has_fields": false,
        "countries": null,
        "availability": null,
        "supports": [
            "products"
        ],
        "order_button_text": null,
        "chosen_gateway": false
    },
    "cod": {
        "id": "cod",
        "method_title": "Cash on delivery",
        "title": "Cash on delivery",
        "description": "Pay with cash upon delivery.",
        "icon": "",
        "icon_urls": "",
        "has_fields": false,
        "countries": null,
        "availability": null,
        "supports": [
            "products"
        ],
        "order_button_text": null,
        "chosen_gateway": false
    },
    "stripe": {
        "id": "stripe",
        "method_title": "Stripe",
        "title": "Credit Card (Stripe)",
        "description": "Pay with your credit card via Stripe.",
        "icon": "<img src=\"https://yourdomain.xyz/wp-content/plugins/woocommerce-gateway-stripe/assets/images/visa.svg\" class=\"stripe-visa-icon stripe-icon\" alt=\"Visa\" /><img src=\"https://yourdomain.xyz/wp-content/plugins/woocommerce-gateway-stripe/assets/images/amex.svg\" class=\"stripe-amex-icon stripe-icon\" alt=\"American Express\" /><img src=\"https://yourdomain.xyz/wp-content/plugins/woocommerce-gateway-stripe/assets/images/mastercard.svg\" class=\"stripe-mastercard-icon stripe-icon\" alt=\"Mastercard\" />",
        "icon_urls": [
            "https://yourdomain.xyz/wp-content/plugins/woocommerce-gateway-stripe/assets/images/visa.svg",
            "https://yourdomain.xyz/wp-content/plugins/woocommerce-gateway-stripe/assets/images/amex.svg",
            "https://yourdomain.xyz/wp-content/plugins/woocommerce-gateway-stripe/assets/images/mastercard.svg"
        ],
        "has_fields": true,
        "countries": null,
        "availability": null,
        "supports": [
            "products",
            "refunds",
            "tokenization",
            "add_payment_method",
            "subscriptions",
            "subscription_cancellation",
            "subscription_suspension",
            "subscription_reactivation",
            "subscription_amount_changes",
            "subscription_date_changes",
            "subscription_payment_method_change",
            "subscription_payment_method_change_customer",
            "subscription_payment_method_change_admin",
            "multiple_subscriptions",
            "pre-orders"
        ],
        "order_button_text": null,
        "chosen_gateway": false
    }
}

Quantities

This API helps you get the quantities of each product added to the cart.

HTTP request

GET
/wp-json/cocart/v1/quantities
curl -X GET https://example.com/wp-json/cocart/v1/quantities \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/quantities",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/quantities",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/quantities' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
  "31": 1,
  "32": 1,
  "36": 2
}

Removed Items

This API helps you get items removed by the customer. This can be helpful should you wish to remind and allow customers to re-add an item back to the cart.

HTTP request

GET
/wp-json/cocart/v1/removed-items
curl -X GET https://example.com/wp-json/cocart/v1/removed-items \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/removed-items",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/removed-items",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/removed-items' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
  "40d8882729aa85d43fe007db12880105": {
    "key": "40d8882729aa85d43fe007db12880105",
    "product_id": 34,
    "variation_id": 0,
    "variation": [],
    "quantity": 1,
    "data_hash": "b5c1d5ca8bae6d4896cf1807cdf763f0",
    "line_tax_data": {
      "subtotal": [],
      "total": []
    },
    "line_subtotal": 20,
    "line_subtotal_tax": 0,
    "line_total": 16,
    "line_tax": 0
  }
}

Shipping Methods

This API helps you get and set shipping methods.

Get Shipping Methods

Returns all available shipping methods once the customer has calculated shipping.

Properties

Attribute Type Description
recurring_cart_key string The recurring cart key identifies each subscription in cart. required, only for subscriptions.

HTTP request

GET
/wp-json/cocart/v1/shipping-methods
curl -X GET https://example.com/wp-json/cocart/v1/shipping-methods \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/shipping-methods",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/shipping-methods",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/shipping-methods' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
  "flat_rate:1":{
    "key": "flat_rate:1",
    "method_id": "flat_rate",
    "instance_id": 1,
    "label": "Flat rate",
    "cost": "33.00",
    "html": "Flat rate: £33.00",
    "taxes": {
      "12": 6.6
    },
    "chosen_method": true
  },
  "free_shipping:3":{
    "key": "free_shipping:3",
    "method_id": "free_shipping",
    "instance_id": 3,
    "label": "Free shipping",
    "cost": "0.00",
    "html": "Free shipping",
    "taxes": [],
    "chosen_method": false
  }
}

Set Shipping Method

Apply a shipping method to the cart. Can only apply once the customer has calculated shipping.

Properties

Attribute Type Description
key string The key of the shipping method. required
recurring_cart_key string The recurring cart key identifies each subscription in cart. required, only for subscriptions.

HTTP request

POST
/wp-json/cocart/v1/shipping-methods
curl -X POST https://example.com/wp-json/cocart/v1/shipping-methods \
  -H "Content-Type: application/json" \
  -d '{
    "key": "free_shipping:3"
  }'
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/shipping-methods",
  "method": "POST",
  "data": {
    "key": "free_shipping:3"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

$args = array(
  "key" => "free_shipping:3"
);

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/shipping-methods",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $args,
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$args = array(
  "key" => "free_shipping:3"
);
$response = wp_remote_post( 'https://example.com/wp-json/cocart/v1/shipping-methods', $args );
$body = wp_remote_retrieve_body( $response );

JSON response example.

true

Totals

This API helps you get all the cart totals including getting them individually.

Get Cart Totals

This API helps you get the cart totals. You can also return the totals pre-formatted to save you time applying the currency symbol. Get Cart Totals properties.

The fee_total, fee_tax and fee_taxes are only updated if the fees are calculated or the totals are calculated once the fees have been added.

HTTP request

GET
/wp-json/cocart/v1/totals
curl -X GET https://example.com/wp-json/cocart/v1/totals \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
  "subtotal":"123.00",
  "subtotal_tax":8.4,
  "shipping_total":"33.00",
  "shipping_tax":6.6,
  "shipping_taxes": {
    "12": 6.6
  },
  "discount_total":24.6,
  "discount_tax":0,
  "cart_contents_total":"98.40",
  "cart_contents_tax":8.4,
  "cart_contents_taxes": {
    "12": 8.4
  },
  "fee_total":"5.00",
  "fee_tax":0.4,
  "fee_taxes":{
    "12": 0.4
  },
  "total":"146.40",
  "total_tax":15,
  "fees": {
    "cocart-extra-package-protection":{
        "id": "cocart-extra-package-protection",
        "name": "Extra Package Protection",
        "amount": "5",
        "taxable": false,
        "tax_class": "",
        "total": 500
    }
  }
}

Get Discount Total

HTTP request

GET
/wp-json/cocart/v1/totals/discount
curl -X GET https://example.com/wp-json/cocart/v1/totals/discount \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/discount",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/discount",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/discount' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"£8.40"

Get Discount Totals

HTTP request

GET
/wp-json/cocart/v1/totals/discount/coupon-totals
curl -X GET https://example.com/wp-json/cocart/v1/totals/discount/coupon-totals \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/discount/coupon-totals",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/discount/coupon-totals",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/discount/coupon-totals' );
$body = wp_remote_retrieve_body( $response );

JSON response example

{
  "blizzard": "£8.40"
}

Get Discount Tax Totals

HTTP request

GET
/wp-json/cocart/v1/totals/discount/coupon-tax
curl -X GET https://example.com/wp-json/cocart/v1/totals/discount/coupon-tax \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/discount/coupon-tax",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/discount/coupon-tax",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/discount/coupon-tax' );
$body = wp_remote_retrieve_body( $response );

Get Fee Total

HTTP request

GET
/wp-json/cocart/v1/totals/fee
curl -X GET https://example.com/wp-json/cocart/v1/totals/fee \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/fee",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/fee",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/fee' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"£40.00"

Get Fee Tax

HTTP request

GET
/wp-json/cocart/v1/totals/fee/tax
curl -X GET https://example.com/wp-json/cocart/v1/totals/fee/tax \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/fee/tax",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/fee/tax",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/fee/tax' );
$body = wp_remote_retrieve_body( $response );

Get Shipping Total

HTTP request

GET
/wp-json/cocart/v1/totals/shipping
curl -X GET https://example.com/wp-json/cocart/v1/totals/shipping \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/shipping",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/shipping",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/shipping' );
$body = wp_remote_retrieve_body( $response );

Get Shipping Tax

HTTP request

GET
/wp-json/cocart/v1/totals/shipping/tax
curl -X GET https://example.com/wp-json/cocart/v1/totals/shipping/tax \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/shipping/tax",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/shipping/tax",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/shipping/tax' );
$body = wp_remote_retrieve_body( $response );

Get Subtotal

HTTP request

GET
/wp-json/cocart/v1/totals/subtotal
curl -X GET https://example.com/wp-json/cocart/v1/totals/subtotal \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/subtotal",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/subtotal",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/subtotal' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"£42.00"

Get Subtotal Tax

HTTP request

GET
/wp-json/cocart/v1/totals/subtotal/tax
curl -X GET https://example.com/wp-json/cocart/v1/totals/subtotal/tax \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/subtotal/tax",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/subtotal/tax",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/subtotal/tax' );
$body = wp_remote_retrieve_body( $response );

Get Cart Total Tax

HTTP request

GET
/wp-json/cocart/v1/totals/tax
curl -X GET https://example.com/wp-json/cocart/v1/totals/tax \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/tax",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/tax",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/tax' );
$body = wp_remote_retrieve_body( $response );

Get Cart Total

HTTP request

GET
/wp-json/cocart/v1/totals/total
curl -X GET https://example.com/wp-json/cocart/v1/totals/total \
 -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/totals/total",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/totals/total",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/totals/total' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"£33.60"

Cart Weight

This API helps you get the cart weight. The weight unit returned is set in your WooCommerce settings.

HTTP request

GET
/wp-json/cocart/v1/weight
curl -X GET https://example.com/wp-json/cocart/v1/weight \
  -H "Content-Type: application/json"
var settings = {
  "url": "https://example.com/wp-json/cocart/v1/weight",
  "method": "GET"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php
$curl = curl_init();

curl_setopt_array( $curl, array(
  CURLOPT_URL => "https://example.com/wp-json/cocart/v1/weight",
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_RETURNTRANSFER => true
) );

$response = curl_exec($curl);

curl_close($curl);

echo $response;
<?php
$response = wp_remote_get( 'https://example.com/wp-json/cocart/v1/weight' );
$body = wp_remote_retrieve_body( $response );

JSON response example

"4 kg"

Changelog

The Documentation is updated only when needed. Below is the changelog for "CoCart Pro" documentation that matches with the version of the plugin release.

Doc Version 0.2 - Plugin Release v1.0.0

Doc Version 0.1 - Plugin Release v1.0.0