Skip to content

Architecture

PSR-4 WCPricebook\src/.

FileResponsibility
wc-pricebook.phpBootstrap: constants, autoload, WC guard, boot, CLI registration
src/Plugin.phpService container; wires hooks and modules in boot()
src/Config.phpAll configuration; option-backed (wc_pricebook_config) and filterable
src/Context.phpResolves the pricing user, manager status, tier & visibility membership
src/PriceEngine.phpThe core: price_as_tier() and price_for_user()
src/Rules.phpNamed behaviors → taxonomy terms / per-product flags
src/WooHooks.phpWooCommerce price / cart / visibility filters
src/Admin/Settings.phpSettings page (tiers, visibility roles)
src/Admin/ProductMeta.phpProduct-data "Pricebook" tab
src/Admin/UserProfile.phpPer-user My Products / include-exclude / category roles
src/Switcher/Manager admin-bar pricing switcher
src/Flowchart/Flowchart.php/price-flowchart debug page
src/Export/Pricelist export: CSV of every user's resolved price (WP-CLI, cron, "Send now")

Design rule

Anything a store needs is reachable from settings/options or a filter — adoption is a data migration, not a code fork. No store-specific IDs, roles, or names live in src/.

Autoloading

The plugin prefers Composer's autoloader if vendor/ exists, else a built-in SPL autoloader in wc-pricebook.php. New classes need no manual wiring.

Development

Requires Docker and Node.

bash
npm install            # @wordpress/env
npm run env:start      # WordPress + WooCommerce at http://localhost:8888 (admin / password)
composer install       # dev deps (PHPUnit) — the plugin runs without Composer
npm test               # vendor/bin/phpunit — standalone, no Docker/DB needed

The PHPUnit suite is standalone: tests/bootstrap.php shims the WP functions the engine uses with an in-memory store, so it's fast and needs no database. Add a test in tests/*Test.php for any engine/context/rules change.

Released under the GPL-2.0-or-later License.