Skip to main content

Retag a subscriber in your email platform whenever their tier changes — whatever handles billing

Premium Intermediate

benecaster_subscription_tier_changed never hears a MemberPress, Paid Memberships Pro, Restrict Content Pro or WooCommerce Subscriptions plan change: those plugins report one as a fresh activation, and Benecaster keeps that path off tier_changed so it does not send the Tier Change email. benecaster_subscription_tier_moved fires once for every source and sends nothing, so it is the hook for retagging.

The move carries no direction. benecaster_compare_tiers() supplies it.

Code

<?php
add_action( 'benecaster_subscription_tier_moved', function ( int $user_id, int $show_id, string $old_tier, string $new_tier ): void {
    $user = get_userdata( $user_id );
    if ( ! $user ) {
        return;
    }

    // 1 = upgrade, -1 = downgrade, 0 = same tier, null = cannot rank (e.g. a tier deleted since).
    $cmp = benecaster_compare_tiers( $show_id, $new_tier, $old_tier );

    my_esp_remove_tag( $user->user_email, 'tier-' . $old_tier );
    my_esp_add_tag( $user->user_email, 'tier-' . $new_tier );
    if ( null !== $cmp && 0 !== $cmp ) {
        my_esp_add_tag( $user->user_email, $cmp > 0 ? 'upgraded' : 'downgraded' );
    }
}, 10, 4 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →