strangerstudios / pmpro-cancel-on-next-payment-date

Change membership cancellation in Paid Memberships Pro to set expiration for next payment date instead of cancelling immediately.
https://www.paidmembershipspro.com/add-ons/cancel-on-next-payment-date
8 stars 8 forks source link

Sometimes you just don't want to permit to completely cancel #42

Open mircobabini opened 1 year ago

mircobabini commented 1 year ago

The current state of the art is to completely cancel if level already has an end date

https://github.com/strangerstudios/pmpro-cancel-on-next-payment-date/blob/dev/pmpro-cancel-on-next-payment-date.php#L82-L83

Level already has an end date. Set to false so we really cancel.

This is not always wanted, at all.

Example 1: Sometimes people are cancelling one more time (after the first time disabling the auto-renewal).

You would say "let's have a gist to remove the cancel button if already set an end date". That's ok.

Example 2: Sometimes people are double clicking the cancellation link, very fast, on the cancel confirmation page.

You would say "we can fix javascript to avoid double clicks". That's ok too.

Describe the solution you'd like

Both examples 1 and 2 deserve their own solution. But when you just don't want to permit a complete cancellation until expiration, there are many ways to break it. Can we just try to think differently?

Instead of trying to fix it from every side, I would hack the exact line which is causing this.

I would replace this:

if ( empty( $check_level ) || ( ! empty( $check_level->enddate ) && '0000-00-00 00:00:00' !== $check_level->enddate ) ) {
    // Level already has an end date. Set to false so we really cancel.
    $pmpro_next_payment_timestamp = false;
}

with

if ( empty( $check_level ) ) {
    // No order found, immediate cancellation.
    $pmpro_next_payment_timestamp = false;
} elseif ( ! empty( $check_level->enddate ) && '0000-00-00 00:00:00' !== $check_level->enddate ) {
    if ( apply_filters( 'pmproconpd_permit_complete_cancellation', true ) ) {
        // Level already has an end date. Set to false so we really cancel.
        $pmpro_next_payment_timestamp = false;
    } else {
        // Leave it untouched. Don't want to cancel.
        // Returning the cancel level instead of 0. This should be enough to keep their membership.

        return $cancel_level;
    }
}

Snippet to disable complete cancellation

// 1. Add the snippet to remove the cancel button if already have an end date.
// ...

// 2. Add the snippet (js) to avoid fast double click the cancel button on cancel confirmation page
// ...

// 3. Then add this filter to disable complete cancellation completely:
add_filter( 'pmproconpd_permit_complete_cancellation', '__return_false' );
mircobabini commented 1 year ago

Since this issue is caused by the cancel page though, I would suggest another approach.

Let's merge into core: