WooCommerce Subscriptions

LicenceForge integrates with the WooCommerce Subscriptions plugin to manage the full subscription lifecycle — activations, suspensions, cancellations, expirations, and renewals — automatically keeping license status in sync with subscription status.

Prerequisite

This integration requires the WooCommerce Subscriptions plugin. The base WooCommerce integration must also be configured. See WooCommerce Integration for setup steps.

Subscription Hooks

LicenceForge listens to the following WooCommerce Subscriptions status change hooks:

WC Subscriptions hook Fires when
woocommerce_subscription_status_active Subscription becomes active (initial activation or reactivation)
woocommerce_subscription_status_on-hold Subscription is placed on hold (payment retry or manual action)
woocommerce_subscription_status_cancelled Subscription is cancelled by the customer or admin
woocommerce_subscription_status_expired Subscription reaches its end date
woocommerce_subscription_renewal_payment_complete A renewal payment is successfully processed

Status Mapping

When a subscription status changes, LicenceForge maps it to the corresponding license action:

Subscription status License action Resulting license status
active Reactivate Active
on-hold Suspend Suspended
cancelled Cancel Cancelled
expired Expire Expired

The mapping ensures that the license always reflects the current state of the subscription. For example, if a customer's payment method fails and the subscription goes on hold, the license is immediately suspended. When the payment succeeds and the subscription returns to active, the license is reactivated.

Implementation example

// Subscription status to license action mapping
$status_map = [
    'active'    => 'reactivate',
    'on-hold'   => 'suspend',
    'cancelled' => 'cancel',
    'expired'   => 'expire',
];

$action = $status_map[ $subscription->get_status() ] ?? null;

if ( $action && $license ) {
    $license->{$action}();
}

Renewal Handling

When the woocommerce_subscription_renewal_payment_complete hook fires, LicenceForge performs two operations:

  1. Reactivates the license — If the license was suspended (e.g., due to a failed payment retry), it is returned to active status.
  2. Updates the period end date — The license's period_end is set to the subscription's next_payment date, extending the license validity to the next billing cycle.
// On renewal payment complete
$next_payment = $subscription->get_date( 'next_payment' );

$license->reactivate();
$license->set_period_end( $next_payment );
$license->save();
Grace period

Between a failed payment and the next retry, the subscription may be on hold and the license suspended. Renewal payment success automatically restores the license without manual intervention.

Subscription Tracking

LicenceForge stores the WooCommerce subscription ID on the license record in the wc_subscription_id field. This enables:

  • Looking up the license from a subscription (or vice versa)
  • Linking status change events to the correct license
  • Displaying subscription details in the LicenceForge admin panel
// Find the license for a subscription
$license = WPLF_License::find_by_meta( 'wc_subscription_id', $subscription->get_id() );

One-Time Purchases

For products sold as one-time purchases (not subscriptions), LicenceForge calculates the license expiry date from the price tier's price_interval setting:

price_interval License expiry
month 1 month from purchase date
year 1 year from purchase date
lifetime No expiry (license never expires)
// Expiry calculation for one-time purchases
switch ( $price_tier->get_interval() ) {
    case 'month':
        $expiry = date( 'Y-m-d H:i:s', strtotime( '+1 month' ) );
        break;
    case 'year':
        $expiry = date( 'Y-m-d H:i:s', strtotime( '+1 year' ) );
        break;
    case 'lifetime':
        $expiry = null; // No expiry
        break;
}
One-time vs. subscription

One-time purchases do not renew automatically. Once the period_end date passes, the license expires unless manually extended. For automatic renewals, use WooCommerce Subscriptions or the Stripe integration.

Lifecycle Summary

The complete subscription-to-license lifecycle:

  1. Purchase — Customer buys a subscription product. License is created via the standard WooCommerce license creation flow.
  2. Active — Subscription is active, license is active. Customer can use the software.
  3. Payment failure — Subscription goes on hold, license is suspended. Activation checks will fail.
  4. Payment retry success — Subscription returns to active, license is reactivated and period extended.
  5. Cancellation — Customer or admin cancels the subscription. License is cancelled.
  6. Expiration — Subscription reaches its end date. License is expired.