Skip to main content

Documentation Index

Fetch the complete documentation index at: https://developer.surecart.com/llms.txt

Use this file to discover all available pages before exploring further.

These actions fire during subscription lifecycle events like renewals.
For handling subscription cancellations and restorations that affect purchase access, see Purchases. The surecart/purchase_revoked and surecart/purchase_invoked actions fire when subscriptions are canceled or restored.

surecart/subscription_renewed

Fires when a subscription successfully renews.
Parameters
Action Parameters
add_action( 'surecart/subscription_renewed', function( $subscription, $data ) {
    // Fetch the subscription with customer relation loaded.
    $subscription = \SureCart\Models\Subscription::with(['customer'])->find( $subscription->id );

    // Send renewal confirmation.
    wp_mail(
        $subscription->customer->email,
        'Subscription Renewed',
        'Thank you! Your subscription has been renewed.'
    );
}, 10, 2 );

Use Cases

Send Renewal Thank You Email

add_action( 'surecart/subscription_renewed', function( $subscription, $data ) {
    // Fetch subscription with customer, price, and product relations loaded.
    $subscription = \SureCart\Models\Subscription::with(['customer', 'price', 'price.product'])->find( $subscription->id );
    
    $customer = $subscription->customer;
    $product = $subscription->price->product ?? null;
    $product_name = is_object( $product ) ? $product->name : 'your subscription';
    
    $subject = 'Thank you for renewing!';
    $message = sprintf(
        "Hi %s,\n\nThank you for your continued support! Your subscription to %s has been renewed.\n\nNext renewal date: %s\n\nBest regards,\nThe Team",
        $customer->first_name ?? 'there',
        $product_name,
        ! empty( $subscription->current_period_end_at ) ? gmdate( 'F j, Y', $subscription->current_period_end_at ) : 'N/A'
    );
    
    wp_mail( $customer->email, $subject, $message );
}, 10, 2 );

Track Renewals for Analytics

add_action( 'surecart/subscription_renewed', function( $subscription, $data ) {
    // Fetch subscription with customer and price relations loaded.
    $subscription = \SureCart\Models\Subscription::with(['customer', 'price'])->find( $subscription->id );
    
    // Track in Google Analytics
    if ( function_exists( 'gtag' ) ) {
        // Server-side tracking
        wp_remote_post( 'https://www.google-analytics.com/mp/collect', [
            'body' => json_encode([
                'client_id' => $subscription->customer->id,
                'events' => [[
                    'name' => 'subscription_renewal',
                    'params' => [
                        'subscription_id' => $subscription->id,
                        'value' => $subscription->price->amount / 100,
                        'currency' => $subscription->price->currency,
                    ]
                ]]
            ])
        ]);
    }
}, 10, 2 );

Notify Team of High-Value Renewals

add_action( 'surecart/subscription_renewed', function( $subscription, $data ) {
    // Fetch subscription with customer and price relations loaded.
    $subscription = \SureCart\Models\Subscription::with(['customer', 'price'])->find( $subscription->id );
    
    $amount = $subscription->price->amount ?? 0;
    
    // Notify for renewals over $500
    if ( $amount >= 50000 ) {
        wp_mail(
            'sales@example.com',
            'High-Value Renewal',
            sprintf(
                'Customer %s just renewed for $%s!',
                $subscription->customer->email,
                number_format( $amount / 100, 2 )
            )
        );
    }
}, 10, 2 );

Purchases

Handle subscription cancellations and restorations via purchase events.

Models

Hook into subscription model events like canceled and restored.