Architecture¶
Overview¶
renewal-discounts is a WooCommerce Subscriptions add-on plugin built as a Composer package. It follows the modular structure defined by barberklingen/base-plugin, where each concern is a singleton Module instantiated from the main RenewalDiscounts class.
Entry point¶
src/RenewalDiscounts.php — bootstrapped by the host project. Calls get_instance() on each module and loads src/functions.php.
Modules¶
| Class | Responsibility |
|---|---|
Migrator | Runs database migrations on boot via the base-plugin Migrator trait |
Subscriptions | Hooks into wcs_renewal_order_created to apply pending discounts |
MetaBoxes | Renders the admin meta box on the subscription edit screen |
Endpoints | Registers REST API controllers on rest_api_init |
AjaxAccountApplyOffboardingDiscount | Handles the front-end AJAX action for applying an offboarding discount from My Account |
Discount scheme strategy pattern¶
DiscountScheme (interface)
└── BaseDiscountScheme (abstract)
├── FixedAmountDiscountScheme
├── PercentageOrderDiscountScheme
└── OffboardingDiscountScheme
DiscountSchemes::schemes() returns the registered map (filterable via renewal-discounts/schemes).
DiscountSchemes::get_scheme(string $enum) instantiates the correct scheme.
Data layer¶
ORM models extend barberklingen/base-plugin base classes:
| Model | Base class | Table |
|---|---|---|
DataDiscountType | ORMModel | {prefix}renewal_discount_types |
DataDiscount | ORMModelWithMeta | {prefix}renewal_discount + meta |
Frontend¶
A Vue.js web component (app/) renders the discount history and type selector in the subscription meta box. Built assets are committed to src/assets/js/.