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

# Hooks reference

> Every action and filter CartPresets exposes, with signatures and worked examples

Hooks are a public API once shipped. Within a major version, none of these will be removed and none will change argument order or count.

> [!NOTE]
>
> Every hook on this page exists in both the free version and Pro unless it's marked Pro. The tables, the REST namespace and the stored values are identical too.

## Terms used on this page

**Safety-clamped**: a limit is re-applied after your filter runs, so a listener can't produce a nonsensical result. Named per hook.

**Additive only**: add keys freely, and the plugin's own are restored afterwards. Removing or rewriting one breaks the feature rather than extending it.

**Seeded conservatively**: the value with no listener attached is the cautious one. Pro attaches at priority 10 like anyone else, so a listener at a later priority still has the last word.

## Lifecycle actions

Every "this happened" hook has a counterpart for when it's undone, so a listener can clean up what it granted without polling.

```php theme={null}
// Presets
do_action( 'cartpresets_after_preset_created',    int $id, array $data );
do_action( 'cartpresets_after_preset_saved',      int $id, array $data );
do_action( 'cartpresets_before_preset_deleted',   int $id, object $preset );
do_action( 'cartpresets_after_preset_deleted',    int $id );
do_action( 'cartpresets_after_preset_duplicated', int $new_id, int $source_id );
do_action( 'cartpresets_preset_status_changed',   int $id, string $new, string $old );

// The cart
do_action( 'cartpresets_before_add_to_cart',           object $preset, array $items, array $verdicts );
do_action( 'cartpresets_after_add_to_cart',            object $preset, array $cart_keys, string $instance_id );
do_action( 'cartpresets_instance_removed_from_cart',   string $instance_id, WC_Cart $cart );

// Purchase limits
do_action( 'cartpresets_before_redemption_recorded', int $preset_id, int $order_id, string $instance );
do_action( 'cartpresets_after_redemption_recorded',  int $preset_id, int $order_id, string $instance );
do_action( 'cartpresets_redemption_limit_exceeded',  int $preset_id, string $limit_type );
do_action( 'cartpresets_redemptions_released',       int $order_id );

// Settings, carrier, lifecycle
do_action( 'cartpresets_after_settings_saved',     array $next, array $previous );
do_action( 'cartpresets_carrier_product_created',  int $product_id );
do_action( 'cartpresets_carrier_product_unlinked' );
do_action( 'cartpresets_activated' );
do_action( 'cartpresets_deactivated' );
do_action( 'cartpresets_loaded' );
do_action( 'cartpresets_cart_hooks_registered' );
do_action( 'cartpresets_register_rest_routes' );
do_action( 'cartpresets_cache_invalidated', int $product_id, int[] $preset_ids );
```

`cartpresets_instance_removed_from_cart` fires whenever a preset leaves the cart as a whole: after a locked line is removed, when a preset is taken out because it's no longer whole, and when one is taken out because an item changed under it.

`cartpresets_after_redemption_recorded` fires once per claim, even when two requests complete the same order at once.

`cartpresets_redemptions_released` is the counterpart to `after_redemption_recorded`. An order leaving the counted statuses gives its slot back, so a listener that granted something on record can revoke it on release.

`cartpresets_carrier_product_created` fires both when the plugin creates a carrier product and when a merchant points it at an existing one. A listener needs to know which product is the carrier, so one hook covers both cases.

### Worked example: grant a membership when a preset is bought

```php theme={null}
add_action( 'cartpresets_after_redemption_recorded', function ( $preset_id, $order_id ) {
	if ( 12 !== (int) $preset_id ) {
		return;
	}

	my_plugin_grant_membership( wc_get_order( $order_id )->get_customer_id() );
}, 10, 2 );
```

There's no registration step and no interface, and it does nothing at all if CartPresets for WooCommerce isn't installed.

## Pricing

```php theme={null}
apply_filters( 'cartpresets_item_source_price', float $base, object $item );
apply_filters( 'cartpresets_item_unit_price',   float $unit, object $item );
apply_filters( 'cartpresets_item_subscription_terms', array $terms, object $item, array $settings );
```

`cartpresets_item_source_price` changes the price the discount is worked out from: the product's regular or sale price, before any preset discount is applied. It runs before the discount formulas, so what you return is discounted exactly as a real price would be.

`cartpresets_item_unit_price` is the last word on what a line costs. **Safety-clamped**: `max( 0, ... )` is re-applied afterwards, so no listener can produce a negative price and hand the customer money.

`cartpresets_item_subscription_terms` decides how far a preset discount reaches into a subscription, as `[ 'payments' => int, 'waive_fee' => bool ]`.

* `payments` counts the payments the discount covers, including the one being made. `0` holds the preset's price on every payment for the life of the subscription. `1` buys the first payment and bills renewals at the product's own price. `3` is one purchase and two discounted renewals.
* `waive_fee` zeroes the product's sign-up fee for that line.

It's seeded with what the free version does: `payments => 0` (every payment), fee charged. Honouring the item's stored payment limit and fee waiver is Pro, and Pro attaches at priority 10 like anyone else, so a listener at a later priority still has the last word. Both settings are stored on either tier.

**Safety-clamped**: a returned array with no `payments` key keeps the seed, so a listener that only answers `waive_fee` can't cut the discount short by accident. The value goes through `absint()`.

A limit of `1` is applied by shared pricing, on both tiers. A limit of `2` or more is put back to the full price after N payments by Pro, which the free version doesn't have. So on free, a listener returning `2` or more gets a discount on every payment.

## Cart

```php theme={null}
apply_filters( 'cartpresets_cart_item_data',      array $data, object $item, object $preset );
apply_filters( 'cartpresets_cart_group_id',       string $instance_id, array $cart_item );
apply_filters( 'cartpresets_item_coupon_allowed', bool $allowed, array $cart_item );
apply_filters( 'cartpresets_clear_cart',          bool $should_clear, int $preset_id, WC_Cart $cart );
apply_filters( 'cartpresets_preset_coupon',       string $code, object $preset, array $settings );
apply_filters( 'cartpresets_post_add_url',        string $url, object $preset );
apply_filters( 'cartpresets_notice_text',         string $text, string $id, bool $is_plural );
```

`cartpresets_cart_item_data` is **additive only**. Append your own keys freely; the plugin's are re-applied afterwards. The integrity rules read them, and a filter rewriting an instance ID would break preset isolation for every other line in the cart.

`cartpresets_cart_group_id` is applied on both sides of every comparison. Override it and "the rest of this preset" changes meaning everywhere, including away from the trigger line. A wider group has to hold every item any of its lines requires, or it'll be taken out as incomplete. The same id is what a checkout holds, what the order line is stamped with and what the redemption row records, so one group counts once against a purchase limit. It's cut to 64 characters, the width of the column that stores it.

Every preset line carries the IDs of the items its preset can't be without. A cart loaded from the session loses any preset that isn't whole, and a line with no such list counts as not whole. Every line also needs its preset item to still exist and point at the same product and variation; one that doesn't takes its preset out with the `cascade_removed` notice.

`cartpresets_clear_cart` decides the outright clear: the whole cart, the customer's own shopping included. It's seeded with the resolved answer: the store's **Clear the existing cart**, or the preset's own when its `cart_override` is on. It fires once per link, before the limit check, so the filter and the removal can't reach different conclusions. The two narrower settings it outranks are only read when it resolves false.

A preset answers all three cart questions or none of them. `cart_override` decides which level is read, and `clear_cart`, `allow_duplicate` and `keep_existing` are its answers when it's on, so one screen tells you how a cart will behave.

`cartpresets_preset_coupon` is seeded empty, and shared code never reads the stored setting itself. With nothing attached, a preset applies no coupon. Honouring the stored code is Pro. The code comes off again once no line of the preset that applied it is left in the cart. A code the customer applied themselves is left alone.

`cartpresets_post_add_url` is **safety-clamped** against the host allow-list.

`cartpresets_notice_text` receives one customer-facing sentence before its values are put in, with the notice ID and whether this is the plural form of a pair. See [Cart notices and wording](https://docs.smartwpplugins.com/cartpresets/links/wording.md).

## Availability and eligibility

```php theme={null}
apply_filters( 'cartpresets_item_is_valid', bool $is_valid, array $verdict );
apply_filters( 'cartpresets_eligibility',   array $result, object $preset );
```

`cartpresets_item_is_valid` is **additive only** in the restrictive direction. It can turn a valid item invalid (a membership gate, a regional rule), but it can't rescue one the plugin has already hard-failed. A deleted product or a missing carrier would make the cart line broken rather than merely unwanted, so the filter isn't applied at all in those cases.

`cartpresets_eligibility` is seeded `allowed => true`, and every verdict comes from a listener, including the plugin's own. On free nothing is attached, so the verdict stays yes.

It's asked when the link is followed and again at every way into payment: the classic checkout, the Blocks checkout and order-pay. Your listener should give the same answer at checkout as it did at the link. Call `PresetUrlHandler::eligibility( $preset )` to ask the same question yourself.

### Worked example: a regional rule

```php theme={null}
add_filter( 'cartpresets_eligibility', function ( $result, $preset ) {
	if ( 'wholesale-kit' !== $preset->slug ) {
		return $result;
	}

	if ( 'GB' !== WC()->customer->get_shipping_country() ) {
		return array(
			'allowed' => false,
			'reason'  => __( 'This offer is only available in the UK.', 'my-plugin' ),
		);
	}

	return $result;
}, 20, 2 );
```

Priority 20 runs after the plugin's own listener, so this has the last word.

## Tier

```php theme={null}
apply_filters( 'cartpresets_is_pro', bool $is_pro );
```

Whether the Pro tier is active. With no filter attached, the answer is whether the Pro code is installed at all. Filter it false and Pro behaves like the free version, which is how you test the free experience without deleting files.

> [!WARNING]
>
> Read this through `Support\Tier::is_pro()` rather than calling the filter yourself, and read it at the moment you decide something, not when you register. Code that filters the tier can load after your listener is attached.

Two more filters make sure a save can't write a field the running tier has no control for:

```php theme={null}
apply_filters( 'cartpresets_preset_premium_fields', array $keep, array $submitted, ?object $preset );
apply_filters( 'cartpresets_premium_settings',      array $keep, array $incoming );
```

Both are seeded with the values already stored. A listener returns the submitted value for the fields it answers for; keys it leaves out keep their seeded value, and keys outside the set are dropped rather than written.

This way, a tier without a control neither sets the field nor disturbs what another tier stored.

`cartpresets_preset_premium_fields` covers `created_at`, `end_at`, `max_total`, `max_per`, `refused_action`, `refused_url`, `refused_notice` and `coupon`. `cartpresets_premium_settings` covers one store-wide key: `redemption_statuses`.

Narrowing which order statuses use up a slot makes a stored cap count fewer orders than the merchant asked it to, which puts a sold-out run back on sale, so it needs Pro. Where a refused customer lands can't do that, however it's set, so the store-wide refusal setting ships free. The per-preset one needs Pro, because a downgrade shouldn't send a customer somewhere other than where the merchant chose.

Neither is a validation step. A rejected value is replaced by the stored one without an error, and the rest of the same save goes through.

## Schema

```php theme={null}
apply_filters( 'cartpresets_settings_defaults',      array $defaults );
apply_filters( 'cartpresets_item_settings_defaults', array $defaults );
```

Register a new key of your own. The plugin's own keys are restored after the filter, so nothing can redefine what `disc_type` means underneath the pricing engine.

Writes walk the schema rather than the payload, so a key you haven't registered here is never saved, whatever a request contains.

## Identity and keys

```php theme={null}
apply_filters( 'cartpresets_generated_slug',          string $slug, string $name, int $exclude_id );
apply_filters( 'cartpresets_redemption_customer_key', string $key );
apply_filters( 'cartpresets_carrier_product_id',      int $product_id );
```

`cartpresets_generated_slug` runs before uniquification, and its result is sanitised. A listener shapes the slug; it can't break the URL.

`cartpresets_redemption_customer_key` decides how "the same customer" is recognised for per-customer limits. Default: `user:<ID>` for a signed-in customer, and `email:<billing email>`, lower-cased, for a guest. Return a stable key per real person.

The two built-in forms answer for each other when a per-customer cap is counted. `user:<ID>` also counts claims under that account's email and billing email, and `email:<address>` also counts claims by an account with that email or billing email. A key of any other shape stands alone.

`cartpresets_carrier_product_id` points custom items at a carrier product other than the configured one. It also decides which product can't be bought on its own: `?add-to-cart=` and the Store API refuse it, and so does checkout. **Safety-clamped**: whatever you return still has to pass the same existence and purchasability checks as a configured ID, so an invalid override is rejected the same way an invalid setting is, instead of producing a broken cart line.

## Purchase limits

```php theme={null}
apply_filters( 'cartpresets_hold_minutes', int $minutes, string $context );
```

How long a claim is held between checkout and payment. A preset instance that passes the checkout gate holds its slot, and counts against `max_total` and `max_per`, until its order reaches a counted status, is cancelled, fails or is refunded, or the hold runs out. **Safety-clamped** to at least one minute.

`$context` says which hold you're setting:

| `$context` | When | Default |
| - | - | - |
| `checkout` | Classic checkout, before the order exists | WooCommerce's **Hold stock (minutes)**, or 60 when that's empty |
| `order` | Once the claim belongs to an order | A day, or the stock hold if that's longer |

`cartpresets_redemption_limit_exceeded` fires with `$limit_type` set to `max_total` or `max_per` when a limit refuses a purchase at checkout. It fires with `paid_over_limit` when a payment arrives after its hold ran out and takes a preset past its limit. That order is counted, not refused, and gets an order note.

## Listing

```php theme={null}
apply_filters( 'cartpresets_list_args',       array $args );
apply_filters( 'cartpresets_listing_revenue', ?array $revenue );
```

`cartpresets_list_args` is the listing's resolved query arguments, after defaults and before any SQL is built. Every key is always present: `search`, `status` (`all`, one derived status, a comma list or an array), `sort` (`name`, `status`, `items`, `price`, `revenue`, `orders` or `publish`) with `dir` (`asc` or `desc`), `per_page`, `page`, and `filters`.

`search` matches a preset's name, slug and note, and the products inside it: product name, variation name, either one's SKU, or a custom item's name.

`filters` takes either the encoded query-string form (`field~op~value` rows joined by `|`, each value percent-encoded) or an array of `{ field, op, value }`:

| Field | Type | Operators | Value |
| - | - | - | - |
| `price` | number | `gt`, `lt`, `eq` | A number |
| `revenue`Pro | number | `gt`, `lt`, `eq` | A number |
| `items` | number | `gt`, `lt`, `eq` | A whole number |
| `orders` | number | `gt`, `lt`, `eq` | A whole number |
| `date` | date | `between`, `after`, `before` | `YYYY-MM-DD`, or `YYYY-MM-DD..YYYY-MM-DD` for `between` |
| `product` | product | `includes` | Text |
| `status` | choice | `is`, `is_not` | A derived status |
| `product_name` | text | `eq`, `contains`, `not_contains`, `starts_with` | Text |
| `coupon` | text | `eq`, `contains`, `not_contains`, `starts_with` | Text |
| `stock_problem` | boolean | `is` | `1` or `0` |

The first six are the ones the listing's **Filters** popover offers. The rest are accepted from code.

`price` is what the customer pays today, worked out from live product prices. `revenue` is WooCommerce's net revenue on the order lines the preset was stamped on: the same figure the listing's Revenue column shows. Both are applied after the SQL rather than inside it. `order_revenue` is also accepted and means `revenue`.

`items` counts a preset's items; `orders` counts its redemptions. `date` compares the publish date in whole days, and every bound is inclusive: `after` includes its own day, `before` runs to the last second of its day, and a `between` written the wrong way round is read as the range you meant. A full date-time is read as its day. `product` makes the same match the search makes.

What you return is validated exactly like a caller's own arguments. An unknown sort key falls back, statuses outside the ladder are dropped, rows outside the allow-lists are dropped, and every value still reaches SQL through `prepare()`.

The REST route takes at most 8 filter rows, and at most 3 from `product`, `product_name` and `stock_problem` together. Those limits are the route's, so rows a listener adds here aren't counted against them.

`cartpresets_listing_revenue` is how the listing learns revenue. It starts as `null`, meaning revenue isn't available. A listener returns an array of preset ID to net revenue as a float, and a preset missing from it counts as zero. It fires at most once per request, and only when a listing query sorts or filters by revenue. The listener returns data, not SQL.

Pro answers it from WooCommerce's Analytics lookup tables, with the same query the Revenue column's figures come from. With nothing answering, as on the free version, the `/presets` route refuses a revenue sort or filter with a 400. `PresetRepository::get_list()` called directly falls back to the default sort and drops the revenue rows.

## Admin picker

```php theme={null}
apply_filters( 'cartpresets_picker_product_types', string[] $types );
```

Which product types the editor's item picker offers. Default: `simple`, `variable`, `subscription`, `variable-subscription`.

External, grouped and composite types are left out because they can't be added to a cart by product ID. Only add a custom type here if it can.

## The admin panel

```php theme={null}
apply_filters( 'cartpresets_admin_boot',  array $data );
apply_filters( 'cartpresets_admin_links', array $links );
```

`cartpresets_admin_boot` is everything the React panel is handed at boot: REST base, the store's clock and currency, the settings, the status ladder, the filter fields, the tier, the store-wide preset counts, the outbound links and the wording catalogue. Append a key and your own screen can read it without a second request on every page load. [The boot payload](https://docs.smartwpplugins.com/cartpresets/developers/javascript.md) lists every key the panel is given.

It's **additive only**. A listener that removes or rewrites an existing key breaks the panel, and nothing downstream checks.

Premium code also uses this seam to publish state that shared code must not know about. Pro adds a `licence` key, with the licence's status and expiry, so the licence card opens in the right state before its own request answers. Shared code can't name a class the free version doesn't ship.

`cartpresets_admin_links` is every address the panel links out to, handed over as the boot payload's `links`:

| Key | Points at |
| - | - |
| `docs` | The documentation's home |
| `quickstart` | The documentation's first page |
| `support` | The WordPress.org support forum |
| `reportIssue` | A new thread there |
| `review` | A new review there |
| `account`Pro | The licence vendor's customer portal. Pro adds it |

Change any value, or add a key for a screen of your own. A value that isn't a URL goes back to the default.

## Order and display

```php theme={null}
apply_filters( 'cartpresets_order_line_item_meta',       array $meta, array $cart_item );
apply_filters( 'cartpresets_badge_text',                 string $text, string $name, string $context );
apply_filters( 'cartpresets_custom_item_shipping_data',  array $shipping, object $item );
apply_filters( 'cartpresets_preset_url',                 string $url, string $slug );
apply_filters( 'cartpresets_admin_capability',           string $capability );
```

`cartpresets_order_line_item_meta` is **additive only**. `cartpresets_custom_item_shipping_data` and `cartpresets_admin_capability` are **safety-clamped**.

`cartpresets_badge_text` rewords the "part of a preset" badge. One filter covers all four places it appears: `$context` is `cart`, `checkout`, `order` or `email`. `$name` is the preset name; in the `order` and `email` contexts that's the name as it was snapshotted when the order was placed, not the preset's name today.

`cartpresets_preset_url` shapes output only. It doesn't affect how an incoming request is parsed. That read path is separate and this filter doesn't rewire it, so changing one keeps the other working.

## ReportingPro

```php theme={null}
apply_filters( 'cartpresets_sales_payload',     array $payload, string $after, string $before, int[] $ids, WP_REST_Request $request );
apply_filters( 'cartpresets_sales_orders_cap',  int $cap, int $preset_id );  // default 100
```

The payload filter runs last, after totals, series, rows and the orders drill-down are assembled. The cap filter raises how many orders the drill-down lists; the table announces truncation either way.

Both fire from Pro only. On free they never fire, and the `cartpresets/v1/sales` routes aren't registered at all. Import and export work the same way.

> [!WARNING]
>
> Check `Support\Tier::is_pro()` before assuming either exists. An integration that needs sales figures on both tiers should read WooCommerce's lookup tables itself, the way this controller does.

## UpdatesPro

```php theme={null}
apply_filters( 'cartpresets_update_manifest_url', string $url );
```

Where Pro looks for its release manifest. The default is `https://smartwpplugins.com/updates/cartpresets-for-woocommerce-pro.json`. Point it elsewhere to run a site on a pre-release channel, or return an empty string to switch automatic updates off for that site entirely.

Fired from the admin and cron only; the storefront never reaches it. The licence is checked before the manifest is fetched, so a filter returning a different URL changes which release a licensed site is offered. It doesn't bypass licensing.

The request is a `GET` with `site` and `version` in the query string, and the licence key in an `X-CartPresets-Licence` header. That lets the update host check the licence before it serves a download. It's never in the URL, because URLs end up in server and CDN logs.

## What is deliberately not exposed

These protect the store, so no hook can weaken them:

* No filter bypasses a capability or nonce check.
* No filter turns a hard validation failure back into a valid item.
* No filter bypasses purchase-limit enforcement at either stage.
* No filter disables cascade removal or weakens instance isolation.
* No filter sits between a query and `$wpdb->prepare()`.
* No PHP filter registers anything the React admin renders.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.