Skip to content

Architecture

Overview

cancellation-reasons is a WooCommerce Subscriptions plugin. It adds admin UI actions (cancel, pause, force-activate) to the subscription detail page and the subscription list, and records the selected cancellation reason(s) in a custom database table.

Entry point

The plugin is bootstrapped by barberklingen/base-plugin, which calls CancellationReasons\Loader::init(). The loader instantiates all modules as singletons via the Module trait.

Modules

Class Responsibility
Modules\PostTypes Enables editor and custom-fields support on the cancellation_reason post type (registered by base-plugin).
Backend\Subscriptions Injects Vue web components into the WooCommerce subscription detail page (woocommerce_admin_order_data_after_order_status) and the subscription list (woocommerce_subscription_list_table_actions).
Backend\MetaBoxes Adds meta box(es) to the subscription edit screen.
Modules\TemporaryPause Listens for auto_reactivation date updates and adds an order note; also aligns the next payment date to the day after the pause ends.
RESTndpoints Registers all REST API controllers on rest_api_init.
Extensions\Klaviyo Sends cancellation events to Klaviyo (requires barberklingen/woocommerce-klaviyo ^3).
Migrations\Migrator Runs database migrations on activation; current version: 1.0.0.

Database

A single custom table (name resolved via RestController::getCancellationReasonsTable()) stores cancellation reason entries:

Column Type Notes
id int Primary key
subscription_id int WooCommerce subscription post ID
reason_id int cancellation_reason post ID
date datetime UTC timestamp of the cancellation action

Flow — cancel a subscription

sequenceDiagram
    actor Admin
    participant CancelButton as Vue <admin-app-cancel>
    participant REST as REST /subscription/{id}/cancellation-reasons
    participant DB as cancellation_reasons table
    participant WC as WooCommerce Subscriptions

    Admin->>CancelButton: clicks Cancel
    CancelButton->>REST: POST reason_post_ids[]
    REST->>DB: INSERT reason rows
    REST->>WC: update subscription status
    REST-->>CancelButton: inserted reasons
    CancelButton-->>Admin: confirmation UI

HPOS compatibility

All subscription reads and writes use the WooCommerce CRUD API (wcs_get_subscription, $subscription->get_id(), etc.) — no direct wp_posts / postmeta access — so the plugin is compatible with WooCommerce High-Performance Order Storage (HPOS).