Enhanced CLAUDE.md with comprehensive project context for future AI sessions: Added sections: - Complete project structure with file descriptions - Architecture overview with all 6 core classes - Detailed data flow diagrams for product creation, display, and cart - Development workflow and testing checklist - Release creation commands - Session history documenting v1.0.0 implementation Key updates: - Documented all architectural decisions made during implementation - Added testing checklist for quality assurance - Included known limitations and future enhancement ideas - Created "For AI Assistants" section with session startup guide - Updated translation section to reflect current .pot template status This documentation will help future sessions understand: - What was built and why - How the system works end-to-end - What needs testing before releases - Areas for future improvement 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
9.6 KiB
WooCommerce plugin for user composable products - AI Context Document
Author: Marco Graetsch
Project Overview
This plugin implements a special product type, for which users can select a limited number of product from a configurable set of simple or variable products. The limit of selectable products should be a global and per-product setting, for which global is the fallback. The set of selectable products can be defined per category, tag or SKU. The price is either a fixed price or the sum of the prices of the selected products. Think of a package of stickers as composable product, where each package can contain $limit number of stickers.
Key Fact: 100% AI-Generated
This project is proudly "vibe-coded" using Claude.AI - the entire codebase was created through AI assistance.
Technical Stack
- Language: PHP 8.3+
- Framework: Latest WordPress Plugin API
- E-commerce: WooCommerce 10.0+
- Template Engine: Twig 3.0 (via Composer)
- Frontend: Vanilla JavaScript + jQuery
- Styling: Custom CSS
- Dependency Management: Composer
- Internationalization: WordPress i18n (.pot/.po/.mo files)
Implementation Details
Security Best Practices
- All user inputs are sanitized (integers for quantities/prices)
- Nonce verification on form submissions
- Output escaping in templates (
esc_attr,esc_html,esc_js) - Direct file access prevention via
ABSPATHcheck
Translation Ready
All user-facing strings use:
__('Text to translate', 'wc-composable-product')
_e('Text to translate', 'wc-composable-product')
Text domain: wc-composable-product
Translation Template:
- Base
.potfile created:languages/wc-composable-product.pot - Ready for translation to any locale
- All translatable strings properly marked with text domain
Planned Translations:
en_US- English (United States) [base language]de_DE- German (Germany, formal)de_DE_informal- German (Germany, informal "du")de_CH- German (Switzerland, formal "Sie")de_CH_informal- German (Switzerland, informal "du")fr_CH- French (Switzerland)it_CH- Italian (Switzerland)
Note: Swiss locales should use CHF currency formatting in examples (e.g., "CHF 50.-")
Create releases
Important Notes
- The
vendor/directory MUST be included in releases (Twig dependency required for runtime) - Running zip from wrong directory creates empty or malformed archives
- Exclusion patterns must match the relative path structure used in zip command
- Always verify the package with
unzip -land test extraction before committing - The
wp-core/andwp-plugins/directories MUST NOT be included in releases!
Important Git Notes:
- Always commit from
devbranch first - Tags should use format
vX.X.X(e.g.,v1.1.22) - Use annotated tags (
-a) not lightweight tags - Commit messages should follow the established format with Claude Code attribution
.claude/settings.local.jsonchanges are typically local-only (stash before rebasing)
What Gets Released
- All plugin source files
- Compiled vendor dependencies
- Translation files (.mo compiled from .po)
- Assets (CSS, JS)
- Documentation (README, CHANGELOG, etc.)
What's Excluded
- Git metadata (
.git/) - Development files (
.vscode/,.claude/,CLAUDE.md) - Logs and cache files
- Previous releases
composer.lock(butvendor/is included)
Project Structure
wc-composable-product/
├── assets/
│ ├── css/
│ │ ├── admin.css # Admin panel styling
│ │ └── frontend.css # Customer-facing styles
│ └── js/
│ ├── admin.js # Product edit interface logic
│ └── frontend.js # AJAX cart & selection UI
├── cache/ # Twig template cache (writable)
├── includes/
│ ├── Admin/
│ │ ├── Product_Data.php # Product data tab & meta boxes
│ │ └── Settings.php # WooCommerce settings integration
│ ├── Cart_Handler.php # Add-to-cart & cart display logic
│ ├── Plugin.php # Main plugin class (Singleton)
│ ├── Product_Selector.php # Frontend product selector renderer
│ └── Product_Type.php # Custom WC_Product extension
├── languages/
│ └── wc-composable-product.pot # Translation template
├── templates/
│ └── product-selector.twig # Frontend selection interface
├── vendor/ # Composer dependencies (gitignored)
├── composer.json # Dependency configuration
├── wc-composable-product.php # Main plugin file
└── [Documentation files] # README, INSTALL, IMPLEMENTATION, etc.
Architecture Overview
Core Classes
-
Plugin.php - Main singleton class
- Initializes Twig template engine
- Registers hooks and filters
- Manages asset enqueuing
- Provides template rendering API
-
Product_Type.php - Custom WooCommerce product type
- Extends
WC_Product - Handles selection criteria (category/tag/SKU)
- Manages pricing modes (fixed/sum)
- Queries available products dynamically
- Extends
-
Cart_Handler.php - Cart integration
- Validates product selections
- Stores selected products in cart meta
- Calculates dynamic pricing
- Displays selections in cart/checkout
-
Product_Selector.php - Frontend renderer
- Renders Twig template with product data
- Applies display settings (images/prices/total)
-
Admin/Product_Data.php - Product edit interface
- Adds "Composable Options" tab
- Category/tag/SKU selection fields
- Saves product metadata
-
Admin/Settings.php - Global settings
- WooCommerce settings tab integration
- Default limits and pricing mode
- Display preferences
Data Flow
Product Creation:
- Admin selects "Composable product" type
- Configures criteria, limits, pricing in product data tab
- Metadata saved:
_composable_*fields
Frontend Display:
Cart_Handler::render_product_selector()called on product pageProduct_Type::get_available_products()queries matching productsProduct_Selector::render()passes data to Twig template- JavaScript handles selection UI and AJAX
Add to Cart:
- Customer selects products (JS validates limit)
- AJAX request with
composable_products[]array Cart_Handler::validate_add_to_cart()server-side validationCart_Handler::add_cart_item_data()stores selectionsCart_Handler::calculate_cart_item_price()applies pricing
Development Workflow
Initial Setup
composer install
Making Changes
- PHP Classes: Edit files in
includes/orincludes/Admin/ - Templates: Modify
templates/*.twig(cache clears on auto-reload) - Styles: Update
assets/css/*.css - JavaScript: Edit
assets/js/*.js - Translations: Update
.potfile, create.potranslations
Testing Checklist
- Create composable product in admin
- Test each selection criteria type (category/tag/SKU)
- Verify selection limit enforcement
- Test both pricing modes (fixed/sum)
- Check AJAX add-to-cart functionality
- Verify cart display shows selected products
- Test checkout process
- Check responsive design on mobile
- Validate all strings are translatable
Creating Releases
# From project root
zip -r wc-composable-product-vX.X.X.zip . \
-x "*.git*" "*.vscode*" "*.claude*" "CLAUDE.md" \
"wp-core" "wp-plugins" "*.log" "composer.lock" \
"cache/*" "releases/*" "*.zip"
# Verify contents
unzip -l wc-composable-product-vX.X.X.zip
# IMPORTANT: Ensure vendor/ is included!
Session History
v1.0.0 - Initial Implementation (2024-12-31)
What was built:
- Complete plugin implementation from scratch
- All 6 core PHP classes with PSR-4 autoloading
- Twig template system integration
- Responsive frontend with AJAX functionality
- Admin interface with WooCommerce integration
- Full i18n support with .pot template
- Comprehensive documentation (README, INSTALL, IMPLEMENTATION)
Key decisions made:
- Used Singleton pattern for main Plugin class
- Twig for templating (per requirements)
- Vanilla JS + jQuery for frontend (WooCommerce standard)
- Grid layout for product selector (responsive)
- AJAX add-to-cart for better UX
- Meta-based configuration storage
Files created: 21 files, 2,628 lines of code
Git workflow:
- Initial commit to
mainbranch - Created
devbranch frommain - Both branches in sync at v1.0.0
What works:
- Product type registration ✓
- Admin product data tab ✓
- Category/tag/SKU selection ✓
- Frontend product selector ✓
- AJAX add-to-cart ✓
- Cart integration ✓
- Pricing calculation (both modes) ✓
Known limitations:
- Currently only simple products in selection (not variable)
- No grouped product support
- No automatic stock deduction for selected items
- Template cache requires manual clearing after updates
Future enhancements to consider:
- Variable product support
- Quantity selection per item
- Visual bundle preview
- Product recommendations
- Stock management integration
- Selection presets/templates
For AI Assistants:
When starting a new session on this project:
- Read this CLAUDE.md file first
- Review IMPLEMENTATION.md for technical details
- Check git log for recent changes
- Verify you're on the
devbranch before making changes - Run
composer installif vendor/ is missing - Test changes before committing
- Follow commit message format with Claude Code attribution
- Update this session history section with learnings
Always refer to this document when starting work on this project. Good luck!