Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it’s on-topic for WordPress Development Stack Exchange.
Closed 4 years ago .
I have managed to find the action where I can add the code for the button, but the problem is that I can’t find how to create a cancel link anywhere. Does anyone know how to do it?
So here is the code I got so far:
function woocommerce_cancel_button() { ?>
<a href="#" class="button view"><?php echo esc_html_x( 'Cancel', 'cancel a subscription', 'woocommerce-subscriptions' ); ?></a>
<?php
}
add_action( 'woocommerce_my_subscriptions_actions', 'woocommerce_cancel_button', 10 );
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 );