# Hooks Source: https://kart.bnomei.com/docs/guides/hooks Updated: 2025-08-08T14:08:35+00:00 Summary: Kirby Kart plugin hooks for cart, wishlist, user, stock, license, error handling, plus Kirby fatal-error callback setup for notifications be it Discord or email ## Hooks The Kirby Kart plugin triggers various hooks which you can use to act upon. Path: site/config/config.php Code (php): ``` [ 'kart.log' => function ($ex): void { // generic logger/exception handler }, 'kart.cart.completed' => function (?User $user = null, ?OrderPage $order = null): void { // fulfillment hook of Cart::complete() }, 'kart.provider.*.checkout' => function (): void { // kart()->provider() }, 'kart.provider.*.cancelled' => function (): void { // kart()->provider() }, 'kart.provider.*.completed' => function (array $data = []): void { // kart()->provider() }, 'kart.stock.updated' => function (StockPage $stock, int $amount): void { // StockPage::updateStock() }, 'kart.user.created' => function (?User $user = null): void { // TIP: use default kirby hook to track delete, or kart.user.softDeleted // TIP: send a magic login email // $user?->sendMagicLink(); // TIP: or a discord notification to yourself }, 'kart.user.softDeleted' => function (?User $user = null): void { // TIP: or a discord notification to yourself }, 'kart.user.signup' => function (?User $user = null): void { // NOTE: this will happen in ADDITION to kart.user.created when the signup form is used }, 'kart.cart.add' => function (ProductPage $product, int $count, ?CartLine $item = null, ?User $user = null): void { // kart()->cart() }, 'kart.cart.remove' => function (ProductPage $product, int $count, ?CartLine $item = null, ?User $user = null): void { // kart()->cart() }, 'kart.cart.clear' => function (?User $user = null): void { // kart()->cart() }, 'kart.wishlist.add' => function (ProductPage $product, int $count, ?CartLine $item = null, ?User $user = null): void { // kart()->wishlist() }, 'kart.wishlist.remove' => function (ProductPage $product, int $count, ?CartLine $item = null, ?User $user = null): void { // kart()->wishlist() }, 'kart.wishlist.clear' => function (?User $user = null): void { // kart()->wishlist() }, 'kart.ratelimit.hit' => function (string $ip, string $key, int $count, int $limit): void { // Ratelimit::check() }, 'kart.order.download' => function (OrderPage $order, int $size, string $token, int $timestamp, string $ip): void { // TIP: use to log downloads // NOTE: to count/limit downloads see templates/order.zip.php }, 'kart.license.activate' => function (array $data): void { // NOTE: Kart does not track the state, that's up to you. see config options. }, 'kart.license.deactivate' => function (array $data): void { // NOTE: Kart does not track the state, that's up to you. see config options. }, 'kart.license.validate' => function (array $data): void { // NOTE: Kart does not track the state, that's up to you. see config options. }, ], // other options ]; ``` ## Fatal Errors You can use Kirby's `fatal`-option callback ([see docs](https://getkirby.com/docs/reference/system/options/fatal)) to get notified about errors happening. Please note that you will need to provide a custom template as well. Path: site/config/config.php Code (php): ``` return [ 'fatal' => function($kirby, $exception) { site()->discord(['content' => $exception->getMessage()]); // or send a mail/sms include $kirby->root('templates') . '/fatal.php'; } ]; ```