Skip to content

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.

  • src/Integrations/WooCommerce/ProductPanel.php
  • src/Integrations/WooCommerce/CheckoutHandler.php
  • src/Integrations/WooCommerce/MyAccountSubscriptions.php
  • templates/myaccount/wplm-licenses.php
  • templates/myaccount/wplm-subscriptions.php

Adds a “License Data” tab to the WooCommerce product data meta box.

Fields saved as post meta:

Meta keyTypePurpose
_wplm_is_licensedcheckboxEnables key delivery for this product
_wplm_key_sourceselectgenerator or pool
_wplm_generator_idnumberWhich generator to use
_wplm_max_activationsnumberOverrides generator default
_wplm_valid_for_daysnumberDays until expiry (0 = never)
_wplm_single_key_multi_seatcheckboxOne key for all qty units in the order item
_wplm_overage_strategyselectdeny, allow_1_25x, allow_2x

save_license_meta() uses wp_unslash() + sanitize_text_field() / absint() on all inputs and saves with update_post_meta().

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 item
do_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.

Registers two My Account endpoints via woocommerce_account_menu_items:

  • wplm-licenses → lists customer’s license keys with truncated display and device count
  • wplm-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.

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.