Each action hook is documented below with its description and usage example.

Installation Hooks

cocart_init

Fires once CoCart has finished loading.
Made available since v3.0.0
Usage
add_action( 'cocart_init', function() {
    // Your code here
});
Defined in: includes/class-cocart.php

cocart_updated

Runs after CoCart has been updated.
Made available since v1.2.0
Usage
add_action( 'cocart_updated', function() {
    // Your code here
});
Defined in: includes/classes/class-cocart-install.php

cocart_installed

Runs after CoCart has been installed.
Made available since v1.2.0
Usage
add_action( 'cocart_installed', function() {
    // Your code here
});
Defined in: includes/classes/class-cocart-install.php

Session Management

cocart_after_session_saved_data

Fires after session data is saved. Parameters
customer_id
int
Customer ID.
data
array
Cart data.
cart_expiration
int
Cart expiration.
cart_source
string
Cart source.
Made available since v4.2.0
Usage
add_action( 'cocart_after_session_saved_data', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/class-cocart-session-handler.php

cocart_load_cart_override

Manipulate the overriding cart before it is set in session.
Made available since v2.1.0
Usage
add_action( 'cocart_load_cart_override', function() {
    // Your code here
});
Defined in: includes/classes/class-cocart-session.php

cocart_load_cart

Manipulate the merged cart before it is set in session.
Made available since v2.1.0
Usage
add_action( 'cocart_load_cart', function() {
    // Your code here
});
Defined in: includes/classes/class-cocart-session.php

cocart_cart_loaded

Fires once a cart has loaded. Can be used to trigger a webhook. Parameters
cart_key
string
The cart key.
Made available since v3.8.0
Usage
add_action( 'cocart_cart_loaded', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/class-cocart-session.php

Cart Updates

cocart_update_cart_before_totals

Fires before the cart has updated via a callback, but before cart totals are re-calculated. Parameters
request
WP_REST_Request
The request object.
controller
object
The cart controller.
Made available since v4.1.0
Usage
add_action( 'cocart_update_cart_before_totals', function() {
    // Your code here
}, 10 );
Defined in: includes/abstracts/abstract-cocart-extension-callback.php

cocart_update_cart_after_totals

Fires after the cart has updated via a callback and the cart totals are re-calculated. Parameters
request
WP_REST_Request
The request object.
controller
object
The cart controller.
Made available since v4.1.0
Usage
add_action( 'cocart_update_cart_after_totals', function() {
    // Your code here
}, 10 );
Defined in: includes/abstracts/abstract-cocart-extension-callback.php

Cart Items Management

cocart_item_added_updated_in_cart

Fires if item was added again to the cart but updated the quantity. Parameters
cart_item_key
string
Item key of the item added again.
item_added
array
Item added to cart again.
new_quantity
int
New quantity of the item.
Made available since v2.1.0
Usage
add_action( 'cocart_item_added_updated_in_cart', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-add-item-controller.php

cocart_item_added_to_cart

Fires once an item has been added to cart. Parameters
item_key
string
Item key of the item added.
item_added
array
Item added to cart.
Made available since v2.1.0
Usage
add_action( 'cocart_item_added_to_cart', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-add-item-controller.php

cocart_item_removed

Fires when an item is removed from the cart. Parameters
current_data
array
The cart item data.
Made available since v2.0.0
Usage
add_action( 'cocart_item_removed', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-item-controller.php

cocart_item_restored

Fires when an item is restored to the cart. Parameters
current_data
array
The cart item data.
Made available since v2.0.0
Usage
add_action( 'cocart_item_restored', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-item-controller.php

cocart_item_quantity_changed

Fires when the quantity of an item in the cart is changed. Parameters
item_key
string
Item key.
new_data
array
Item data.
Made available since v2.0.0
Usage
add_action( 'cocart_item_quantity_changed', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-item-controller.php

Cart Operations

cocart_before_cart_emptied

Triggers before the cart is emptied.
Made available since v1.0.0
Usage
add_action( 'cocart_before_cart_emptied', function() {
    // Your code here
});
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-clear-cart-controller.php

cocart_cart_emptied

Triggers once the cart is emptied.
Made available since v1.0.0
Usage
add_action( 'cocart_cart_emptied', function() {
    // Your code here
});
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-clear-cart-controller.php

cocart_cart_cleared

Triggers once the cart is cleared.
Made available since v1.0.0
Usage
add_action( 'cocart_cart_cleared', function() {
    // Your code here
});
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-clear-cart-controller.php

cocart_get_cart

Fires when the cart is retrieved. Parameters
cart_contents
array
Cart contents.
Made available since v2.0.0
Usage
add_action( 'cocart_get_cart', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/cart/class-cocart-controller.php

Extensions

cocart_register_extension_callback

Fires when an extension callback is registered. Parameters
cart_extension
CoCart_Cart_Extension
Instance of the CoCart_Cart_Extension class which exposes the CoCart_Cart_Extension::register() method.
Made available since v3.1.0
Usage
add_action( 'cocart_register_extension_callback', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/class-cocart-cart-extension.php

Product Reviews

cocart_insert_product_review

Fires after a comment is created via the REST API. Parameters
review
WP_Comment
Inserted comment object.
request
WP_REST_Request
The request object.
creating
bool
True when creating a comment, false when updating.
Made available since v2.0.0
Usage
add_action( 'cocart_insert_product_review', function() {
    // Your code here
}, 10 );
Defined in: includes/classes/rest-api/controllers/v1/products/class-cocart-product-reviews-controller.php

Deprecated

cocart_update_cart_before_totals

Deprecated: 4.1.0 Replaced with cocart_update_cart_before_totals hook.
Fires after the cart has updated via a callback.
Made available since v3.1.0
Usage
add_action( 'cocart_update_cart_before_totals', function() {
    // Your code here
});
Defined in: includes/classes/rest-api/callbacks/update-cart.php