CartThrob Credits Version 1.21
Overview
CartThrob Credits lets members purchase credits and spend those credits against cart totals.
Core behavior in current package:
- Credits are stored per member in
cartthrob_credits_credits. - Credit redemptions are tracked in
cartthrob_credits_redemptions. - Credits can be auto-applied during checkout through extension processing.
- Credits can also be added through dedicated credit forms/actions.
Requirements
- ExpressionEngine 2.5+
- CartThrob 2.2+
- PHP 5.3+
Installation
- Upload
cartthrob_creditsto/system/expressionengine/third_party/. - Install
CartThrob Creditsfrom the Add-ons page. - Configure settings in the add-on control panel.
Upgrading
- Upload updated
cartthrob_creditsfiles over the existing add-on. - Run add-on updates from the EE Add-ons page.
- Recheck Credits settings.
Start Here (10-Minute Setup)
- Open
Add-ons > CartThrob Credits > System Settings. - Set
Default Conversion Rate. - Set
Order Channel Credits Fieldif you want credits used written onto order entries. - Set
Auto Apply Creditsbased on your checkout model. - Add test credits to your account in
Add/Edit Credits. - Place
{exp:cartthrob_credits:cart_total_minus_credits}and{exp:cartthrob_credits:credits}in your checkout templates.
Common Tasks With Examples
1. Show Member Credit Balance
{exp:cartthrob_credits:credits}
2. Show Cart Total After Credits
{exp:cartthrob_credits:cart_total_minus_credits}
3. Sell a Product That Grants Credits
{exp:cartthrob_credits:add_to_cart_form entry_id="{entry_id}" credits="10" return="cart/index"}
<input type="submit" value="Buy and add 10 credits" />
{/exp:cartthrob_credits:add_to_cart_form}
4. Add Credits From a Form Action
{exp:cartthrob_credits:add_credit_form price="20" return="account/credits"}
<button type="submit">Buy Credits</button>
{/exp:cartthrob_credits:add_credit_form}
Quick Links For Existing Users
- Need conversion behavior: see
System Settings. - Need member balances: see
Credits List. - Need redemption reporting: see
Redemptions. - Need tag reference: see
Template Tags.
Control Panel Reference
Credits List (.../view)
Table columns:
- Member info (
screen_name, ID, member CP link) - Credit total
- Actions (
Edit,Delete)
Redemptions (.../redemptions)
Table columns:
- Member info
- Credits redeemed
- Amount
- Order ID (or processing/offsite status)
- Date
- Redemption status
Add Credits (.../add)
Form fields:
member_idcredits
Submit creates a credit row or updates member credits through save logic.
Edit Credits (.../edit)
Form fields:
member_idcreditsdelete_creditcheckbox
Delete Credits (.../delete)
Form fields:
- hidden
id deletecheckbox confirmation
System Settings (.../system_settings)
Form fields:
default_conversion_rateorder_channel_credits_fieldauto_apply_credits(true/false)
Template Tags
cart_total_minus_credits
Outputs cart total after applying available member credits.
Parameters:
member_id(optional; defaults to logged-in member)order_by(optional)limit(optional)offset(optional)
Example:
{exp:cartthrob_credits:cart_total_minus_credits}
credits
Outputs total credits for the resolved member.
Parameters:
member_id(optional; defaults to logged-in member)
Example:
{exp:cartthrob_credits:credits}
credits_data
Tag pair for credit row data.
Parameters:
member_id(optional; defaults to logged-in member)order_by(optional)limit(optional)offset(optional)
Variables (from credits row):
idmember_idorder_idtimestampexpiresstatusdescriptioncredits
Conditional:
{if no_results}...{/if}
redemptions
Tag pair for redemption row data.
Parameters:
order_id(optional; when set, redemption query is by order)member_id(optional; defaults to logged-in member whenorder_idnot set)order_by(optional)limit(optional)offset(optional)
Variables (from redemption row):
idmember_idorder_idtimestampcredits_usedamountstatuscart_id
Conditional:
{if no_results}...{/if}
add_to_cart_form
Creates a CartThrob add-to-cart form with credits support.
Parameters:
- standard
cartthrob:add_to_cart_formparameters credits(optional override for credit amount granted)logged_out_redirect(optional)
Behavior:
- if
creditsis set, that value is stored for the cart item - if
creditsis not set, a marker is stored so conversion-rate logic can be used
add_credit_form
Creates a form that posts to Credits add_credit_action.
Parameters:
price(optional encoded amount)order_id(optional encoded order source)allow_user_price(optional)return/secure_return(optional)logged_out_redirect(optional)
Checkout and Processing Behavior
Extension hooks used by the add-on:
cartthrob_pre_processcartthrob_on_authorizecartthrob_on_failcartthrob_on_declinecartthrob_add_to_cart_end
High-level flow:
- Pre-process can apply available credits and reduce checkout total.
- A redemption record is created while processing.
- On authorization, redemption is finalized and order linkage is written.
- If a credit product is purchased, credits are added to the member account.
- On fail/decline, redemption state is rolled back appropriately.