Skip to main content

Developer Hooks

This page documents the key developer hooks available for managing the Divi Engine Membership subscription lifecycle. These hooks allow you to run custom code when subscriptions are created, renewed, cancelled, or refunded - especially useful when integrating with unsupported payment gateways or custom logic.

Subscription Hooks

Using these hooks, you can take full control of subscription behavior in your own codebase. This is essential when working outside of built-in payment providers or extending functionality to suit unique business needs.

How Subscriptions Are Created

When a user subscribes to a membership plan, the plugin creates a new post of type dmem_subscription:

$subscription_post_id = wp_insert_post( array(
'post_type' => 'dmem_subscription',
'post_status' => 'dmem_active',
'post_author' => $user_id,
'post_title' => $plan_title,
) );

After creation, the following post meta fields are typically added:

  • payment_method (e.g. 'stripe', 'paypal', or 'n/A')
  • subscription_id (external ID for gateway, if any)
  • membership_plan (plan post ID)
  • start_date / next_payment_date
  • cycle_key (e.g. 'monthly', 'annually')

This post acts as the internal record for managing the user's subscription status, billing state, and access.

Hook: dmem_subscription_created

Fired after a new dmem_subscription post is created.

do_action('dmem_subscription_created', $subscription_post_id);

Example

add_action('dmem_subscription_created', function($subscription_post_id) {
$user_id = get_post_field('post_author', $subscription_post_id);
$plan_id = get_post_meta($subscription_post_id, 'membership_plan', true);
$payment_method = get_post_meta($subscription_post_id, 'payment_method', true);

if ($payment_method === 'n/A') {
My_Custom_Gateway::create_subscription($subscription_post_id, $user_id, $plan_id);
}
});

Subscription Renewed

Hook: dmem_subscription_renewed

Fired when a subscription is successfully renewed (including manual retries).

do_action('dmem_subscription_renewed', $subscription_id);

Example

add_action('dmem_subscription_renewed', function($subscription_id) {
My_Custom_Gateway::renew_subscription($subscription_id);
});

Subscription Retried

The retry_subscription() method reuses the same hook as renewal:

Also uses: dmem_subscription_renewed

This ensures consistent handling of both scheduled and retried payments.


Subscription Cancelled

Hook: dmem_subscription_cancelled

Fired when a subscription is cancelled and not handled by a built-in gateway.

do_action('dmem_subscription_cancelled', $subscription_id);

Example

add_action('dmem_subscription_cancelled', function($subscription_id) {
My_Custom_Gateway::cancel_subscription($subscription_id);
});

Subscription Refunded

Hook: dmem_subscription_refunded

Fired when a refund is issued for a subscription outside of Stripe or PayPal.

do_action('dmem_subscription_refunded', $subscription_id);

Example

add_action('dmem_subscription_refunded', function($subscription_id) {
My_Custom_Gateway::refund_subscription($subscription_id);
});

Integration Tip

To ensure your custom logic is used instead of Stripe/PayPal, set:

update_post_meta($subscription_post_id, 'payment_method', 'n/A');

This prevents the default gateway logic from running, and instead triggers your own hook handlers.


Summary of Hooks

ActionHook NameParameters
Createdmem_subscription_created$subscription_post_id
Renewdmem_subscription_renewed$subscription_id
Retrydmem_subscription_renewed$subscription_id
Canceldmem_subscription_cancelled$subscription_id
Refunddmem_subscription_refunded$subscription_id

These hooks allow complete control over the subscription lifecycle with custom or unsupported payment methods.