Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shahidbahader/7407f0687033674df4ad6a81fa42d6ed to your computer and use it in GitHub Desktop.
Save shahidbahader/7407f0687033674df4ad6a81fa42d6ed to your computer and use it in GitHub Desktop.
Remove any given button from the My Subscriptions table on the My Account page. By default, only the "Change Payment Method" button is removed, but you can uncomment additional actions to remove those buttons also.
<?php
/**
* Plugin Name: Remove Subscription Action Buttons from My Account
* Plugin URI: https://gist.github.com/thenbrent/8851287/
* Description: Remove any given button from the <a href="http://docs.woothemes.com/document/subscriptions/customers-view/#section-2">My Subscriptions</a> table on the My Account page. By default, only the "Change Payment Method" button is removed, but you can uncomment additional actions to remove those buttons also.
* Author: Brent Shepherd
* Author URI:
* Version: 2.0
*/
/**
* Remove the "Change Payment Method" button from the My Subscriptions table.
*
* This isn't actually necessary because @see eg_subscription_payment_method_cannot_be_changed()
* will prevent the button being displayed, however, it is included here as an example of how to
* remove just the button but allow the change payment method process.
*/
function eg_remove_my_subscriptions_button( $actions, $subscription ) {
foreach ( $actions as $key => $action ) {
switch ( $key ) {
case 'change_payment_method': // Hide "Change Payment Method" button?
// case 'change_address': // Hide "Change Address" button?
// case 'switch': // Hide "Switch Subscription" button?
// case 'resubscribe': // Hide "Resubscribe" button from an expired or cancelled subscription?
// case 'pay': // Hide "Pay" button on subscriptions that are "on-hold" as they require payment?
// case 'reactivate': // Hide "Reactive" button on subscriptions that are "on-hold"?
// case 'cancel': // Hide "Cancel" button on subscriptions that are "active" or "on-hold"?
unset( $actions[ $key ] );
break;
default:
error_log( '-- $action = ' . print_r( $action, true ) );
break;
}
}
return $actions;
}
add_filter( 'wcs_view_subscription_actions', 'eg_remove_my_subscriptions_button', 100, 2 );
@shahidbahader
Copy link
Author

shahidbahader commented Jun 14, 2019

For version 2.5.0 onward, this is the updated file. you can view the changes in Revisions.

@SteveClikk
Copy link

Thanks for this, I was wondering why the original wasn't working.

@AlexisJamin
Copy link

Hi @SteveClikk @shahidbahader

This code does not work. I have WC Subscriptions v3.0.10 and the button still appears :

Capture d’écran 2020-12-06 à 20 12 01

Capture d’écran 2020-12-06 à 20 16 34

Any idea ?

Thanks for your help ! 😊🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment