Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active November 29, 2018 17:19
Show Gist options
  • Save jrick1229/2c2bc30eaa430e978ebb9ca4a919b736 to your computer and use it in GitHub Desktop.
Save jrick1229/2c2bc30eaa430e978ebb9ca4a919b736 to your computer and use it in GitHub Desktop.
Add a 'Cancel' button to the Subscriptions page in the My Account area
<?php
function wcs_add_cancel_button_on_subscriptions_page($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='$cancelLink' class='button cancel'>".$action['name']."</a>";
}
}
}
}
add_action( 'woocommerce_my_subscriptions_actions', 'wcs_add_cancel_button_on_subscriptions_page', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment