> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cocartapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clear the cart

> Removes all items from the customer's cart.




## OpenAPI

````yaml api-reference/v2/openapi-v2-stable.yaml post /cart/clear
openapi: 3.0.3
info:
  title: CoCart - Cart API v2
  version: 4.6.0
  description: >
    CoCart REST API v2 for managing shopping carts, products, and store
    functionality.

    Compared to API v1, this version provides enhanced endpoints for cart
    operations, product management,

    and administrative functions with improved response structures and better
    error handling.
  termsOfService: http://cocartapi.com/terms-of-conditions-polar/
  contact:
    email: support@cocartapi.com
  license:
    name: GNU General Public License v3.0
    url: http://www.gnu.org/licenses/gpl-3.0.html
servers:
  - url: '{protocol}://{host}/wp-json/cocart/v2'
    description: API v2
    variables:
      protocol:
        enum:
          - http
          - https
        default: https
      host:
        default: example-store.com
        description: Your store domain
security: []
tags:
  - name: cart
    description: Operations for managing the shopping cart
  - name: cart-items
    description: Operations for managing cart items
  - name: cart-calculate
    description: Operations for calculating cart totals
  - name: products
    description: Operations for browsing and retrieving product information
  - name: product-attributes
    description: Operations for retrieving product attributes and attribute terms
  - name: product-categories
    description: Operations for browsing and filtering product categories
  - name: product-tags
    description: Operations for browsing and filtering product tags
  - name: product-reviews
    description: Operations for retrieving product reviews and ratings
  - name: product-variations
    description: Operations for retrieving variable product variations
  - name: admin-sessions
    description: Administrative operations for managing cart sessions
  - name: authentication
    description: Operations for user authentication
  - name: store
    description: Operations for retrieving store information and configuration
externalDocs:
  description: Find out more about CoCart API
  url: https://docs.cocartapi.com
paths:
  /cart/clear:
    post:
      tags:
        - cart
      summary: Clear cart
      description: |
        Removes all items from the customer's cart.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                keep_removed_items:
                  description: Keeps removed items in session when clearing the cart.
                  type: boolean
                  default: false
      responses:
        '200':
          description: Cart cleared successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CartV2'
        '400':
          description: Bad request - invalid parameters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: cocart_invalid_parameter
                message: Invalid parameter provided.
                data:
                  status: 400
        '406':
          description: Cart clearing failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: cocart_clear_cart_failed
                message: Clearing the cart failed.
                data:
                  status: 406
components:
  schemas:
    CartV2:
      type: object
      description: Complete cart object with enhanced v2 structure.
      properties:
        cart_hash:
          type: string
          description: Unique cart hash.
        cart_key:
          type: string
          description: Unique cart key for the customer.
        currency:
          $ref: '#/components/schemas/Currency'
        customer:
          $ref: '#/components/schemas/Customer'
        items:
          type: object
          description: Cart items indexed by item key.
          additionalProperties:
            $ref: '#/components/schemas/CartItem'
        item_count:
          type: integer
          description: Total number of items in cart.
        items_weight:
          type: number
          description: Total weight of all items.
        coupons:
          type: array
          description: Applied coupons.
          items:
            $ref: '#/components/schemas/AppliedCoupon'
        needs_payment:
          type: boolean
          description: Whether the cart needs payment.
        needs_shipping:
          type: boolean
          description: Whether the cart needs shipping.
        shipping:
          $ref: '#/components/schemas/Shipping'
        fees:
          type: array
          description: Cart fees.
          items:
            $ref: '#/components/schemas/CartFee'
        taxes:
          type: array
          description: Cart taxes.
          items:
            $ref: '#/components/schemas/CartTax'
        totals:
          $ref: '#/components/schemas/CartTotals'
        removed_items:
          type: array
          description: Recently removed items that can be restored.
          items:
            $ref: '#/components/schemas/RemovedItem'
        cross_sells:
          type: array
          description: Cross-sell products.
          items:
            $ref: '#/components/schemas/CrossSellItem'
        notices:
          type: object
          description: Cart notices and messages.
          additionalProperties: true
        extensions:
          type: object
          description: Additional data from extensions.
          additionalProperties: true
    ErrorResponse:
      type: object
      description: Standard error response structure.
      properties:
        code:
          type: string
          description: Machine-readable error code.
          example: cocart_invalid_parameter
        message:
          type: string
          description: Human-readable error message.
          example: Invalid parameter provided.
        data:
          type: object
          description: Additional error data.
          properties:
            status:
              type: integer
              description: HTTP status code.
              example: 400
            params:
              type: object
              description: Parameter-specific error details.
              additionalProperties: true
          additionalProperties: true
    Currency:
      type: object
      properties:
        currency_code:
          type: string
          description: Currency code.
        currency_symbol:
          type: string
          description: Currency symbol.
        currency_symbol_pos:
          type: string
          description: Currency symbol position.
        currency_minor_unit:
          type: integer
          description: Currency minor unit.
        currency_decimal_separator:
          type: string
          description: Currency decimal separator.
        currency_thousand_separator:
          type: string
          description: Currency thousand separator.
        currency_prefix:
          type: string
          description: Currency prefix.
        currency_suffix:
          type: string
          description: Currency suffix.
    Customer:
      type: object
      properties:
        billing_address:
          $ref: '#/components/schemas/BillingAddress'
        shipping_address:
          $ref: '#/components/schemas/ShippingAddress'
    CartItem:
      type: object
      properties:
        item_key:
          type: string
          description: Unique identifier for the item within the cart.
        id:
          type: integer
          description: Product ID.
        name:
          type: string
          description: Product name.
        title:
          type: string
          description: Product title.
        price:
          type: string
          description: Current product price.
        quantity:
          type: object
          description: Quantity information for this item.
          properties:
            value:
              type: number
              description: Current quantity of the item in the cart.
            min_purchase:
              type: number
              description: Minimum quantity that can be purchased.
            max_purchase:
              type: number
              description: Maximum quantity that can be purchased.
        totals:
          type: object
          description: Item totals.
          properties:
            subtotal:
              type: number
              description: Line subtotal (before discounts).
            subtotal_tax:
              type: number
              description: Line subtotal tax.
            total:
              type: number
              description: Line total (after discounts).
            tax:
              type: number
              description: Line total tax.
        slug:
          type: string
          description: Product slug.
        meta:
          type: object
          description: Item metadata.
          properties:
            product_type:
              type: string
              description: Product type.
            sku:
              type: string
              description: Product SKU.
            dimensions:
              type: object
              description: Product dimensions.
              properties:
                length:
                  type: string
                  description: Product length.
                width:
                  type: string
                  description: Product width.
                height:
                  type: string
                  description: Product height.
                unit:
                  type: string
                  description: Dimension unit.
            weight:
              type: string
              description: Product weight.
            variation:
              description: Chosen attributes (for variations).
              oneOf:
                - type: object
                  additionalProperties:
                    type: string
                - type: array
                  items:
                    type: string
          additionalProperties: true
        backorders:
          type: string
          description: Backorder status.
        cart_item_data:
          type: object
          description: Custom cart item data.
          additionalProperties: true
        featured_image:
          type: string
          description: Product featured image URL.
    AppliedCoupon:
      type: object
      properties:
        coupon:
          type: string
        label:
          type: string
        saving:
          type: string
        saving_html:
          type: string
    Shipping:
      type: object
      properties:
        total_packages:
          type: integer
          description: Number of shipping packages.
        show_package_details:
          type: boolean
          description: Whether to show package details.
        has_calculated_shipping:
          type: boolean
          description: Whether shipping has been calculated.
        packages:
          type: object
          description: Shipping packages.
          additionalProperties:
            $ref: '#/components/schemas/ShippingPackage'
    CartFee:
      type: object
      properties:
        name:
          type: string
        amount:
          type: number
        taxable:
          type: boolean
        tax_class:
          type: string
        total:
          type: number
        tax:
          type: number
    CartTax:
      type: object
      properties:
        rate_id:
          type: integer
        label:
          type: string
        compound:
          type: boolean
        tax_total:
          type: string
        shipping_tax_total:
          type: string
    CartTotals:
      type: object
      properties:
        subtotal:
          type: string
          description: Cart subtotal.
        subtotal_tax:
          type: string
          description: Cart subtotal tax.
        shipping_total:
          type: string
          description: Shipping total.
        shipping_tax:
          type: string
          description: Shipping tax.
        shipping_taxes:
          type: array
          items:
            type: number
        discount_total:
          type: string
          description: Discount total.
        discount_tax:
          type: string
          description: Discount tax.
        cart_contents_total:
          type: string
          description: Cart contents total.
        cart_contents_tax:
          type: string
          description: Cart contents tax.
        cart_contents_taxes:
          type: array
          items:
            type: number
        fee_total:
          type: string
          description: Fee total.
        fee_tax:
          type: string
          description: Fee tax.
        fee_taxes:
          type: array
          items:
            type: number
        total:
          type: string
          description: Cart total.
        total_tax:
          type: string
          description: Total tax.
    RemovedItem:
      type: object
      properties:
        key:
          type: string
        product_id:
          type: integer
        quantity:
          type: integer
        name:
          type: string
    CrossSellItem:
      type: object
      properties:
        id:
          type: integer
        product_name:
          type: string
        product_title:
          type: string
        price:
          type: string
        regular_price:
          type: string
        sale_price:
          type: string
        product_image:
          type: string
    BillingAddress:
      type: object
      properties:
        billing_first_name:
          type: string
        billing_last_name:
          type: string
        billing_company:
          type: string
        billing_country:
          type: string
        billing_address_1:
          type: string
        billing_address_2:
          type: string
        billing_postcode:
          type: string
        billing_city:
          type: string
        billing_state:
          type: string
        billing_phone:
          type: string
        billing_email:
          type: string
    ShippingAddress:
      type: object
      properties:
        shipping_first_name:
          type: string
        shipping_last_name:
          type: string
        shipping_company:
          type: string
        shipping_country:
          type: string
        shipping_address_1:
          type: string
        shipping_address_2:
          type: string
        shipping_postcode:
          type: string
        shipping_city:
          type: string
        shipping_state:
          type: string
    ShippingPackage:
      type: object
      properties:
        package_name:
          type: string
          description: Package name.
        rates:
          type: object
          description: Available shipping rates.
          additionalProperties:
            $ref: '#/components/schemas/ShippingRate'
        package_details:
          type: string
          description: Package details.
        index:
          type: integer
          description: Package index.
        chosen_method:
          type: string
          description: Chosen shipping method.
        formatted_destination:
          type: string
          description: Formatted destination address.
    ShippingRate:
      type: object
      properties:
        key:
          type: string
        method_id:
          type: string
        instance_id:
          type: integer
        label:
          type: string
        cost:
          type: string
        html:
          type: string
        taxes:
          type: string
        chosen_method:
          type: boolean

````