-1

I want to hide the cancel subscription button within the subscription details in 'My Account', before the last 2 days of subscription renewal.

For example, the subscription renewal date of 30 Oct 2022 and the cancel button should hide on 28 Oct 2022, however, the Cancel button still shows.

1 Answers1

1
function jk_remove_cancel_button( $actions, $subscription_id ) {

    // Gets the subscription object on subscription id
    $subscription = new WC_Subscription( $subscription_id );
  
    $next_payment_date = $subscription->get_date( 'next_payment', 'site' );

    $nt = strtotime($next_payment_date);
    $local_time  = current_datetime();
    $ct = $local_time->getTimestamp() + $local_time->getOffset();
  
    // Get the difference in date
    $diff = $ct - $nt;
    $final = abs(round($diff / 86400));
    // Change the number (days) according to your choice
    if ($final <= "2") {
        unset( $actions['cancel'] );
    }
  
    // Return the actions
    return $actions;
} add_filter( 'wcs_view_subscription_actions', 'jk_remove_cancel_button', 100, 2);

This code will hide cancel subscription button before 2 days of subscription renewal.

Tested Perfectly.