Phase 15: WooCommerce Integration
Integrate WPLM into WooCommerce so that licensed products can be configured in the product editor, license keys are delivered automatically on order completion, and customers can manage their keys and subscriptions from My Account.
Files Written
Section titled “Files Written”src/Integrations/WooCommerce/ProductPanel.phpsrc/Integrations/WooCommerce/CheckoutHandler.phpsrc/Integrations/WooCommerce/MyAccountSubscriptions.phptemplates/myaccount/wplm-licenses.phptemplates/myaccount/wplm-subscriptions.php
ProductPanel
Section titled “ProductPanel”Adds a “License Data” tab to the WooCommerce product data meta box.
Fields saved as post meta:
| Meta key | Type | Purpose |
|---|---|---|
_wplm_is_licensed | checkbox | Enables key delivery for this product |
_wplm_key_source | select | generator or pool |
_wplm_generator_id | number | Which generator to use |
_wplm_max_activations | number | Overrides generator default |
_wplm_valid_for_days | number | Days until expiry (0 = never) |
_wplm_single_key_multi_seat | checkbox | One key for all qty units in the order item |
_wplm_overage_strategy | select | deny, allow_1_25x, allow_2x |
save_license_meta() uses wp_unslash() + sanitize_text_field() / absint() on all inputs and saves with update_post_meta().
CheckoutHandler
Section titled “CheckoutHandler”Hooks woocommerce_order_status_completed.
Delivery algorithm:
foreach order_item: if _wplm_is_licensed != '1': skip if _wplm_keys_delivered meta already set: skip (idempotent guard)
$qty = get item quantity
if _wplm_single_key_multi_seat: generate 1 key with max_activations = qty × product_max attach to order item else: for i in range(qty): generate 1 key attach to order item
set _wplm_keys_delivered = 1 on order itemdo_action('wplm_order_licenses_issued', $order, $license_ids)Refund handling (woocommerce_order_refunded): suspends all licenses attached to the refunded order. Suspension (not termination) allows reactivation if the refund dispute is reversed.
MyAccountSubscriptions
Section titled “MyAccountSubscriptions”Registers two My Account endpoints via woocommerce_account_menu_items:
wplm-licenses→ lists customer’s license keys with truncated display and device countwplm-subscriptions→ lists subscriptions with pause/resume/cancel actions
Pause/resume/cancel POST to admin-post.php?action=wplm_sub_action. The handle_sub_action() method verifies:
wp_verify_nonce( $_POST['_wpnonce'], 'wplm_sub_action_' . $sub_id );Then checks that the subscription belongs to the current user before delegating to RenewalProcessor / SubscriptionRepository.
Key Display in Templates
Section titled “Key Display in Templates”License keys in the My Account table are truncated for security:
substr($key, 0, 4) . '-****-****-' . substr($key, -4)// "ABCD-****-****-WXYZ"Customers can copy the full key from the product delivery email, which is sent by woocommerce_email_order_items with the full key.