Developer guide
1. Architecture overview
- Free plugin (
wallet-ready-gift-cards-for-woocommerce) — required base: product type, cart, orders, PDF, email, redeem, Blocks Store API, security, ePasscard integration. - Pro plugin (
wallet-ready-gift-cards-for-woocommerce-pro) — optional: license gate, checkout edit, AI, REST, bulk import, etc. Self-disables if free is inactive. Runtime Pro modules load only whenwallregi_pro_license_is_active()is true (wallregi_pro_bootstrap()in Pro main file).
Loader: includes/initialize-giftcard.php. Bootstrap: wallet-ready-gift-cards-for-woocommerce.php.
2. Important files and folders
| Path | Role |
|---|---|
backend/backend.php | Admin menu, product type, AJAX, settings save |
frontend/frontend.php | Product template, cart item data, order issuance |
frontend/coupon-integration.php | Classic apply/redeem, cart fees |
frontend/blocks/class-wallregi-blocks-integration.php | Store API + Blocks JS settings |
includes/database-functions.php | Tables, helpers, wallregi_normalize_giftcard_preferred_datetime() |
includes/wallregi-manual-giftcard-create.php | wallregi_insert_manual_giftcard() |
includes/wallregi-checkout-receiver.php | Billing/shipping recipient merge at checkout |
includes/wallregi-fraud-safeguards.php | Rate limits + audit log |
includes/wallregi-pro-capabilities.php | Pro license check; checkout-edit gate; strip Pro-only settings when unlicensed |
includes/class-wallregi-pro-admin-placeholders.php | Disabled Pro settings UI when Pro not licensed |
includes/wallregi-ai-hooks.php | Free stubs: wallregi_ai_is_enabled(), etc. |
includes/class-wallregi-wallet-epass-*.php | ePasscard API + issuance |
wallet-ready-gift-cards-for-woocommerce-pro/ | Pro: license, checkout edit, AI, bulk import, REST, … |
docs/EXTENSIONS-ROADMAP.md | Engineering roadmap and hook contract |
3. Database tables
Created on activation via wallregi_create_database_tables() in includes/database-functions.php.
| Table | Purpose |
|---|---|
{prefix}wx_gift_cards | Issued cards: code, amounts, recipient, schedule, status, epass_data JSON |
{prefix}wx_giftcard_transaction | Ledger: purchase, redeem, adjustments |
{prefix}wallregi_security_audit | Security audit events |
{prefix}wallregi_pro_expiry_reminder_log | Pro: sent reminder log |
{prefix}wallregi_pro_expiry_optouts | Pro: unsubscribe list |
4. Options and product meta
4.1 Options
wallregi_settings— General, form, PDF styling, fraud; Pro keys when licensedwallregi_email_settings— Email templateswallregi_pro_license— Pro license payload (signed)wallregi_pro_ai_settings— Pro AI provider, credits, messageswallregi_pro_expiry_reminder_settings— Pro expiry emails
4.2 Product meta (wxgiftcard)
_wallregi_checkout_receiver_address—'',billing, orshipping_wallregi_enable_email_schedule—yes/no- Price rows, expiry fields — see
backend/backend.phpsave handler - Pro:
_wallregi_pro_product_greeting_presets_raw, etc.
4.3 Cart line
Cart items store giftcard_data array (recipient fields, price, image URL, checkout_receiver_source, etc.).
Line totals: wallregi_apply_giftcard_prices_to_cart() (in frontend/frontend.php) sets each gift card product’s price from giftcard_data['giftcard_price'] on woocommerce_before_calculate_totals and after cart-edit saves. Required because direct cart_contents edits do not always pass through woocommerce_cart_contents_changed.
5. Pro licensing and capability gates
wallregi_pro_license_is_active()— strict check (Pro plugin).wallregi_pro_is_licensed()— same, callable from free plugin (includes/wallregi-pro-capabilities.php).wallregi_checkout_giftcard_edit_is_enabled( $settings )— applies filterwallregi_is_checkout_edit_enabledwith default false; Pro sets true when licensed andgiftcard_edit_in_checkout === 'yes'.wallregi_strip_pro_only_settings()— clears Pro-only keys on save when not licensed.- Admin:
admin.php?page=wx-gift-cards-pro-license· classWALLREGI_Pro_License.
6. Programmatic gift card creation
$id = wallregi_insert_manual_giftcard( array(
'giftcard_number' => '', // empty = auto-generate
'auto_generate' => true,
'initial_amount' => 100,
'current_amount' => 100,
'expiry_period' => '+1 year',
'preferred_date_time' => '', // normalized via wallregi_normalize_giftcard_preferred_datetime()
'receipent_name' => 'Jane Doe',
'receipent_email' => 'jane@example.com',
'sender_name' => 'Store',
'message' => 'Enjoy!',
'order_id' => 0,
'item_id' => 0,
'product_id' => 123,
) );
if ( is_wp_error( $id ) ) {
// handle error
}
Pro bulk import and admin manual create both use this function. Filter: wallregi_manual_giftcard_code_format_valid.
7. Hooks and filters (free plugin)
Prefer these over editing core files. Full list also in docs/EXTENSIONS-ROADMAP.md.
7.1 Cart, checkout, edit
| Hook | Type | Use |
|---|---|---|
wallregi_is_cart_edit_enabled | filter | Enable cart edit UI |
wallregi_is_checkout_edit_enabled | filter | Enable checkout edit (default false; Pro sets true when licensed + setting) |
wallregi_is_cart_item_edit_enabled | filter | Per-line edit button (classic item_data) |
wallregi_editable_giftcard_fields | filter | Which fields appear in edit modal |
wallregi_giftcard_cart_edit_payload | filter | Augment data for modal / Blocks |
wallregi_giftcard_data_after_checkout_receiver_merge | filter | After billing/shipping merge |
wallregi_after_giftcard_cart_item_updated | action | After cart line update |
wallregi_after_giftcard_added_to_cart | action | After add to cart |
7.2 Redeem / session
| Hook | Type | Use |
|---|---|---|
wallregi_validate_giftcard_session_limits_before_apply | filter | Return WP_Error to block apply |
wallregi_validate_applied_giftcard_amount_totals_after_apply | filter | Validate totals after apply |
wallregi_max_combined_giftcard_discount_amount | filter | Cap discount during fee calculation |
wallregi_giftcard_apply_checkout_url | filter | QR / deep link URL |
7.3 Email, PDF, wallet
wallregi_send_giftcard_email— action to send (args: code, context array)wallregi_epass_pass_issued/wallregi_epass_pass_updated— wallet pass lifecyclewallregi_blocks_settings— filter JS config for Blocks integrationwallregi_admin_dashboard_tabs/wallregi_sidebar_menu_items— admin UI extension
8. WooCommerce Store API (Blocks)
Class: WALLREGI_Blocks_Integration in frontend/blocks/class-wallregi-blocks-integration.php.
- Namespace:
wallet-ready-gift-cards-for-woocommerce - Cart extension:
appliedGiftcards(codes + formatted amounts) - Cart item extension:
isGiftCard,giftcardData,displayPrice,customPrices,gallery, etc. - Update callback:
update_cart_giftcard— same fields as classic AJAX edit
Frontend: frontend/assets/js/blocks/blocks-integration.js registers checkout filters and handles apply/redeem UI.
9. REST API Pro
Class: WALLREGI_Pro_Giftcard_Rest. Namespace: wc/v3 (WooCommerce REST authentication).
POST /wp-json/wc/v3/wallregi-giftcards/lookup
Content-Type: application/json
{ "giftcard_number": "YOUR-CODE" }
GET /wp-json/wc/v3/wallregi-giftcards/{giftcard_number}/transactions
Permission: manage_woocommerce or WooCommerce manager read; filter wallregi_pro_rest_giftcard_read_allowed.
10. AI assistant Pro
Requires valid Pro license. Option wallregi_pro_ai_settings; admin wx-gift-cards-ai. Classes in Pro includes/ai/; AJAX wallregi_pro_ai_generate. Custom copy: WALLREGI_AI_Messages + admin “Customize messages” on AI settings.
| Hook | Type | Use |
|---|---|---|
wallregi_ai_enabled | filter | Site-wide AI (Pro maps saved settings + API key) |
wallregi_ai_storefront_enabled | filter | Buyer greeting suggest/improve |
wallregi_ai_before_request | action | Before credits/provider ($task, $context, $params) |
wallregi_ai_after_request | action | After successful generation |
wallregi_security_allow_pro_ai_generate | filter | Fraud module IP/admin rate limits on AI AJAX |
wallregi_ai_buyer_error_message | filter | Override shopper error text |
wallregi_ai_admin_error_message | filter | Override admin error text |
Helpers: wallregi_ai_is_enabled(), wallregi_ai_storefront_is_enabled() in includes/wallregi-ai-hooks.php (Pro maps real settings when licensed).
11. Security module
includes/wallregi-fraud-safeguards.php — rate limits on apply, form submit, cart edit, admin actions. Pro endpoints use wallregi_security_allow_pro_* filters (including AI generate).
Audit log table + admin screen wallregi_security. Hook: wallregi_security_audit_log( $event, $status, $context ).
12. Pro-only hooks
| Hook | When |
|---|---|
wallregi_pro_bulk_import_row_before_insert | Filter row before insert |
wallregi_pro_bulk_giftcard_imported | Action after CSV row imported |
wallregi_pro_expiry_reminder_send | Return false to skip email |
wallregi_pro_expiry_reminder_placeholders | Filter merge tags |
wallregi_pro_greeting_presets_parsed | Filter preset chips |
wallregi_validate_buyer_redeem_amount_for_apply | Pro partial redeem validation |
13. Example: add a field to the edit modal
add_filter( 'wallregi_editable_giftcard_fields', function ( $fields, $key, $data, $context ) {
$fields[] = 'my_custom_field';
return $fields;
}, 10, 4 );
add_filter( 'wallregi_giftcard_cart_edit_payload', function ( $giftcard, $cart_item ) {
$giftcard['my_custom_field'] = 'default';
return $giftcard;
}, 10, 2 );
Then handle save in your own AJAX or extend the Store API update callback via free plugin patches (advanced).
14. Development standards
- Sanitize all input; escape all output.
- Use
manage_woocommerce(or stricter) for admin actions. - Nonces on AJAX admin and storefront mutations.
- HPOS: gift card tables are custom; order reads should use WooCommerce order APIs.
- Text domain:
wallet-ready-gift-cards-for-woocommerce(Pro may usewallet-ready-gift-cards-for-woocommerce-profor Pro-only strings).