> ## 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.

# Action hooks available in the core of CoCart

> Trigger an action when these hooks are called

<Info>
  Each action hook is documented below with its description and usage example.
</Info>

## Installation Hooks

### `cocart_init`

Fires once the CoCart plugin has finished loading.

<Info>
  Made available since v3.0.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_init', function() {
    // Your code here
});
```

[Search `cocart_init` in repository](https://github.com/co-cart/co-cart/search?q=cocart_init\&type=code)

***

### `cocart_updated`

Runs after CoCart has been updated.

<Info>
  Made available since v1.2.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_updated', function() {
    // Your code here
});
```

[Search `cocart_updated` in repository](https://github.com/co-cart/co-cart/search?q=cocart_updated\&type=code)

***

### `cocart_installed`

Runs after CoCart has been installed.

<Info>
  Made available since v1.2.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_installed', function() {
    // Your code here
});
```

[Search `cocart_installed` in repository](https://github.com/co-cart/co-cart/search?q=cocart_installed\&type=code)

***

## Session Management

### `cocart_after_session_saved_data`

Fires after session data is saved.

<Info>
  Made available since v4.2.0
</Info>

**Parameters**

<ParamField path="customer_id" type="int">
  Customer ID.
</ParamField>

<ParamField path="data" type="array">
  Cart data.
</ParamField>

<ParamField path="cart_expiration" type="int">
  Cart expiration.
</ParamField>

<ParamField path="cart_source" type="string">
  Cart source.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_after_session_saved_data', function() {
    // Your code here
}, 10 );
```

[Search `cocart_after_session_saved_data` in repository](https://github.com/co-cart/co-cart/search?q=cocart_after_session_saved_data\&type=code)

***

### `cocart_load_cart_override`

Manipulate the overriding cart before it is set in session.

<Info>
  Made available since v2.1.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_load_cart_override', function() {
    // Your code here
});
```

[Search `cocart_load_cart_override` in repository](https://github.com/co-cart/co-cart/search?q=cocart_load_cart_override\&type=code)

***

### `cocart_load_cart`

Manipulate the merged cart before it is set in session.

<Info>
  Made available since v2.1.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_load_cart', function() {
    // Your code here
});
```

[Search `cocart_load_cart` in repository](https://github.com/co-cart/co-cart/search?q=cocart_load_cart\&type=code)

***

### `cocart_cart_loaded`

Fires once a cart has loaded. Can be used to trigger a webhook.

<Info>
  Made available since v3.8.0
</Info>

**Parameters**

<ParamField path="cart_key" type="string">
  The cart key.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_cart_loaded', function() {
    // Your code here
}, 10 );
```

[Search `cocart_cart_loaded` in repository](https://github.com/co-cart/co-cart/search?q=cocart_cart_loaded\&type=code)

***

## Cart Updates

### `cocart_update_cart_before_totals`

Fires before the cart has updated via a callback, but before cart totals are re-calculated.

<Info>
  Made available since v4.1.0
</Info>

**Parameters**

<ParamField path="request" type="WP_REST_Request">
  The request object.
</ParamField>

<ParamField path="controller" type="object">
  The cart controller.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_update_cart_before_totals', function() {
    // Your code here
}, 10 );
```

[Search `cocart_update_cart_before_totals` in repository](https://github.com/co-cart/co-cart/search?q=cocart_update_cart_before_totals\&type=code)

***

### `cocart_update_cart_after_totals`

Fires after the cart has updated via a callback and the cart totals are re-calculated.

<Info>
  Made available since v4.1.0
</Info>

**Parameters**

<ParamField path="request" type="WP_REST_Request">
  The request object.
</ParamField>

<ParamField path="controller" type="object">
  The cart controller.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_update_cart_after_totals', function() {
    // Your code here
}, 10 );
```

[Search `cocart_update_cart_after_totals` in repository](https://github.com/co-cart/co-cart/search?q=cocart_update_cart_after_totals\&type=code)

***

## Cart Items Management

### `cocart_item_added_updated_in_cart`

Fires if item was added again to the cart but updated the quantity.

<Info>
  Made available since v2.1.0
</Info>

**Parameters**

<ParamField path="cart_item_key" type="string">
  Item key of the item added again.
</ParamField>

<ParamField path="item_added" type="array">
  Item added to cart again.
</ParamField>

<ParamField path="new_quantity" type="int">
  New quantity of the item.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_item_added_updated_in_cart', function() {
    // Your code here
}, 10 );
```

[Search `cocart_item_added_updated_in_cart` in repository](https://github.com/co-cart/co-cart/search?q=cocart_item_added_updated_in_cart\&type=code)

***

### `cocart_item_added_to_cart`

Fires once an item has been added to cart.

<Info>
  Made available since v2.1.0
</Info>

**Parameters**

<ParamField path="item_key" type="string">
  Item key of the item added.
</ParamField>

<ParamField path="item_added" type="array">
  Item added to cart.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_item_added_to_cart', function() {
    // Your code here
}, 10 );
```

[Search `cocart_item_added_to_cart` in repository](https://github.com/co-cart/co-cart/search?q=cocart_item_added_to_cart\&type=code)

***

### `cocart_item_removed`

Fires when an item is removed from the cart.

<Info>
  Made available since v2.0.0
</Info>

**Parameters**

<ParamField path="current_data" type="array">
  The cart item data.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_item_removed', function() {
    // Your code here
}, 10 );
```

[Search `cocart_item_removed` in repository](https://github.com/co-cart/co-cart/search?q=cocart_item_removed\&type=code)

***

### `cocart_item_restored`

Fires when an item is restored to the cart.

<Info>
  Made available since v2.0.0
</Info>

**Parameters**

<ParamField path="current_data" type="array">
  The cart item data.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_item_restored', function() {
    // Your code here
}, 10 );
```

[Search `cocart_item_restored` in repository](https://github.com/co-cart/co-cart/search?q=cocart_item_restored\&type=code)

***

### `cocart_item_quantity_changed`

Fires when the quantity of an item in the cart is changed.

<Info>
  Made available since v2.0.0
</Info>

**Parameters**

<ParamField path="item_key" type="string">
  Item key.
</ParamField>

<ParamField path="new_data" type="array">
  Item data.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_item_quantity_changed', function() {
    // Your code here
}, 10 );
```

[Search `cocart_item_quantity_changed` in repository](https://github.com/co-cart/co-cart/search?q=cocart_item_quantity_changed\&type=code)

***

## Cart Operations

### `cocart_before_cart_emptied`

Triggers before the cart is emptied.

<Info>
  Made available since v1.0.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_before_cart_emptied', function() {
    // Your code here
});
```

[Search `cocart_before_cart_emptied` in repository](https://github.com/co-cart/co-cart/search?q=cocart_before_cart_emptied\&type=code)

***

### `cocart_cart_emptied`

Triggers once the cart is emptied.

<Info>
  Made available since v1.0.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_cart_emptied', function() {
    // Your code here
});
```

[Search `cocart_cart_emptied` in repository](https://github.com/co-cart/co-cart/search?q=cocart_cart_emptied\&type=code)

***

### `cocart_cart_cleared`

Triggers once the cart is cleared.

<Info>
  Made available since v1.0.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_cart_cleared', function() {
    // Your code here
});
```

[Search `cocart_cart_cleared` in repository](https://github.com/co-cart/co-cart/search?q=cocart_cart_cleared\&type=code)

***

### `cocart_get_cart`

Fires when the cart is retrieved.

<Info>
  Made available since v2.0.0
</Info>

**Parameters**

<ParamField path="cart_contents" type="array">
  Cart contents.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_get_cart', function() {
    // Your code here
}, 10 );
```

[Search `cocart_get_cart` in repository](https://github.com/co-cart/co-cart/search?q=cocart_get_cart\&type=code)

***

## Extensions

### `cocart_register_extension_callback`

Fires when an extension callback is registered.

<Info>
  Made available since v3.1.0
</Info>

**Parameters**

<ParamField path="cart_extension" type="CoCart_Cart_Extension">
  Instance of the CoCart\_Cart\_Extension class which exposes the CoCart\_Cart\_Extension::register() method.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_register_extension_callback', function() {
    // Your code here
}, 10 );
```

[Search `cocart_register_extension_callback` in repository](https://github.com/co-cart/co-cart/search?q=cocart_register_extension_callback\&type=code)

***

## Product Reviews

### `cocart_insert_product_review`

Fires after a comment is created via the REST API.

<Info>
  Made available since v2.0.0
</Info>

**Parameters**

<ParamField path="review" type="WP_Comment">
  Inserted comment object.
</ParamField>

<ParamField path="request" type="WP_REST_Request">
  The request object.
</ParamField>

<ParamField path="creating" type="bool">
  True when creating a comment, false when updating.
</ParamField>

**Usage**

```php theme={"system"}
add_action( 'cocart_insert_product_review', function() {
    // Your code here
}, 10 );
```

[Search `cocart_insert_product_review` in repository](https://github.com/co-cart/co-cart/search?q=cocart_insert_product_review\&type=code)

***

## Deprecated

### `cocart_update_cart_before_totals`

<Warning>**Deprecated:** 4.1.0 Replaced with `cocart_update_cart_before_totals` hook.</Warning>

Fires after the cart has updated via a callback.

<Info>
  Made available since v3.1.0
</Info>

**Usage**

```php theme={"system"}
add_action( 'cocart_update_cart_before_totals', function() {
    // Your code here
});
```

[Search `cocart_update_cart_before_totals` in repository](https://github.com/co-cart/co-cart/search?q=cocart_update_cart_before_totals\&type=code)

***
