How do I add a “Cancel” button on the subscriptions listing page [closed]

I was looking for the same thing but couldn’t find it anywhere so I tried to do it myself. Here’s my code by the way. Hope this helps.

function addCancelButton($subscription) {
    $actions = wcs_get_all_user_actions_for_subscription( $subscription, get_current_user_id() );
    if(!empty($actions)){
        foreach ( $actions as $key => $action ){
            if(strtolower($action['name']) == "cancel"){
                $cancelLink = esc_url( $action['url'] );
                echo "<a href="https://wordpress.stackexchange.com/questions/292246/$cancelLink" class="button cancel">".$action['name']."</a>";
            }
        }
    }
}
add_action( 'woocommerce_my_subscriptions_actions', 'addCancelButton', 10 );