A customer can usually cancel a membership in his dashboard. How can i restrict this (hide the cancel button) for a specific membership?

I found this code for general hide the cancel button, work’s so far:

function sv_edit_my_memberships_actions( $actions )
    unset( $actions['cancel'] );
    return $actions}
add_filter( 'wc_memberships_my_account_my_memberships_actions', 'sv_edit_my_memberships_actions' );

maybe with this function?

wc_memberships_is_user_active_member( $current_user_id, 'membership-name' )

Read more here: WooCommerce Membership Cancel in WordPress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: