CartThrob Fees Version 4.0.1
Overview
CartThrob Fees adds automatic fee line items to the cart based on cart/customer context and fee rules defined in the control panel.
In current released code, fee rules can target:
- any cart (
AUTO) - per item
- item option matches (
each,once,once per product) - custom cart data key/value
- customer info fields (including gateway)
Fee line items are written as cart items with:
entry_id = nulltitle = fee nameprice = computed fee totalquantity = fee quantityno_shipping = true
Requirements
- ExpressionEngine 6.0+
- CartThrob 6.1+
- PHP 7.1+ (
composer.json)
Installation
- Upload
/cartthrob_fees/to/system/user/addons/. - Install
CartThrob Feesfrom the Add-ons page. - Open
Add-ons > CartThrob Feesand create fee rows. - Save and run a cart test to confirm matching rules apply.
Upgrading
- Upload the new add-on files, replacing the existing
cartthrob_feesfolder. - Run add-on updates from the Add-ons page.
- Re-open
CartThrob Feessettings and verify all fee rows.
Upgrading From Versions Prior To 3.0.0
Version 3.0.0 introduced schema/model changes:
cartthrob_fees_settingsgained primary keyid.- Legacy serialized flag handling in settings was removed in favor of native serialized handling.
- Legacy
cartthrob_fees_tablewas replaced withcartthrob_fees. - Fee records are stored as rows (not serialized fee bundles).
get_feesoutputs both formatted and numeric fee values via:numericvariables.
Start Here (10-Minute Setup)
- Go to
Add-ons > CartThrob Fees. - Add one row with:
- Fee Name: Handling Fee
- Price: 4.95
- Percent: leave blank
- Apply Field: AUTO
- Key: leave blank
- Match Value: GLOBAL
- Are fees taxable?: No (or Yes if needed)
3. Save.
4. Add an item to cart and output:
- {exp:cartthrob_fees:fees_total}
- {exp:cartthrob_fees:get_fees}...{/exp:cartthrob_fees:get_fees}
5. Confirm fee appears in cart totals and fee loop output.
Common Tasks With Examples
1. Add A Flat Fee For Every Cart
- Use
field = AUTO - Set
price(leavepercentempty) - Use
value = GLOBAL
2. Add A Percentage-Based Fee
- Use
field = AUTO(or a conditional field) - Set
percent(leavepriceempty) - Fee is calculated from subtotal before fees
3. Add Item Option Fees
item_options_key_each: evaluates matching items and applies per matching item passitem_options_key_once: applies once for a given key/value match setitem_options_key_once_per_product: applies once per unique product (entry_id)
4. Add Customer-Context Fees
Use customer info fields like country_code, state, email_address, gateway, etc., with value set to either a specific match or GLOBAL.
Quick Links For Existing Users
- Need all fee rows: see Settings Grid Columns
- Need match field options: see Apply Field Values
- Need runtime behavior: see How Fees Are Calculated
- Need tag surface: see Template Tags
Control Panel Reference
Primary route: addons/settings/cartthrob_fees
Main Screen
Screen content is one editable grid of fee rows.
Save behavior in current code:
- Save clears all existing fee rows for current site
- then inserts all submitted rows from the grid
- row reorder is disabled in the grid config
Settings Grid Columns
Fee Name(name)
- Label/name for the fee line item.
Price(price)
- Flat fee amount.
- If both price and percent are provided, code paths prioritize price.
Percent of subtotal(percent)
- Percent-based fee amount used when price is empty.
Apply fee when customer info equals match value(field)
- Selects the rule type and customer/item context to match.
(or) Apply fee when this custom_data/item_options key equals match value(key)
- Used by custom-data and item-option fee types.
match value (use GLOBAL to match any)(value)
- Matching value for selected rule.
- New row default is GLOBAL.
Are fees taxable?(taxable)
- Yes/No toggle for tax treatment.
Apply Field Values
Current field dropdown options in code:
AUTO(Any Field)per_itemitem_options_key_eachitem_options_key_onceitem_options_key_once_per_productcustom_data_key- Customer fields:
address,address2,card_type,city,company,country_code,currency_code,description,email_address,first_name,gateway,group_id,ip_address,language,last_name,phone,region,screen_name,state,shipping_address,shipping_address2,shipping_city,shipping_company,shipping_country_code,shipping_first_name,shipping_last_name,shipping_option,shipping_state,shipping_zip,use_billing_info,username,zip
Utilities > Install
Route: addons/settings/cartthrob_fees/install
Purpose:
- installs bundled template groups/templates from
installer/templates/
Behavior:
- choose template groups via checkbox list
- submit to
do_installation - success/failure alerts are shown inline
How Fees Are Calculated
Runtime Hooks
Extension hooks include:
cartthrob_add_to_cart_startcartthrob_save_customer_info_endcartthrob_update_cart_endcartthrob_delete_from_cart_endcartthrob_pre_processcartthrob_calculate_total
Processing Flow
- Existing fee meta and previously-added fee line items are cleared.
- Fee rows are loaded from
cartthrob_feestable for currentsite_id. - Matching fee strategy object is created from each row.
- Fee value is calculated from either subtotal or item list, depending on type.
- Matching fee objects are stored in cart meta
cartthrob_fees. - Fee line items are added back into cart.
Template Tags
This add-on exposes tags via both patterns:
- module form:
{exp:cartthrob_fees:...} - CartThrob addon registration form:
{exp:cartthrob:...}
get_fees
Tag pair that loops through active fees currently applied to cart.
Examples:
{exp:cartthrob_fees:get_fees}
{fee_name}: {fee_total}
{/exp:cartthrob_fees:get_fees}
{exp:cartthrob:get_fees}
{fee_name}: {fee_total}
{/exp:cartthrob:get_fees}
Parameters:
- none in current implementation
Pair variables (from code):
{fee_name}{fee_price}(formatted){fee_price:numeric}(raw numeric){fee_percent}{field_name}{custom_data_key}{custom_data}{taxable}{fee_total}(formatted){fee_total:numeric}(raw numeric){item_price}(item-based fee types){quantity}(item-based fee types)
Conditional:
{if no_results}...{/if}
fees_total
Outputs total of all active fees in cart.
Examples:
{exp:cartthrob_fees:fees_total}
{exp:cartthrob_fees:fees_total:numeric}
Parameters:
- no named parameters
- optional tag segment suffix
:numericreturns unformatted raw number
Changelog
Version 4.0.1
Release January 18, 2022
- FIXED: Control panel fee update notification was deferred and not displaying on save.
- FIXED: Item Option fees incorrectly creating empty fees when item option did not match.
Version 4.0.0
Release January 11, 2022
- ADDED: New “Item Options (once per product)” fee type.
- ADDED: ExpressionEngine 6+, CartThrob 6+ support.
Version 3.0.0
Release December 13, 2021
- ADDED: CartThrob 5+ support.
Version 2.0.1
Release June 06, 2019
- FIXED: Per Item Fee where fee was not applied per item.
Version 2.0.0
Release March 11, 2019
- ADDED: CartThrob 4+ support.