Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 $action_key => $action ) {
switch ( $action_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[ $action_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 );
@tcltd

This comment has been minimized.

Show comment Hide comment
@tcltd

tcltd Jun 10, 2015

hey! nice script here, wanted to ask if you can edit this slightly to add a custom button to each subscription too?

tcltd commented Jun 10, 2015

hey! nice script here, wanted to ask if you can edit this slightly to add a custom button to each subscription too?

@rvpatel

This comment has been minimized.

Show comment Hide comment
@rvpatel

rvpatel Jul 9, 2015

Hello,
i want a remove cancel button which order has not completed 2 months please help us.

ex. i have purchase 2 products.
1th pro. complete 3 months after purchase date.
2nd.pro.complete 1 months after purchase date.

2nd product user cancle but 1product not.
Reply as soon as possible to me.

rvpatel commented Jul 9, 2015

Hello,
i want a remove cancel button which order has not completed 2 months please help us.

ex. i have purchase 2 products.
1th pro. complete 3 months after purchase date.
2nd.pro.complete 1 months after purchase date.

2nd product user cancle but 1product not.
Reply as soon as possible to me.

@Onyx-VueCare

This comment has been minimized.

Show comment Hide comment
@Onyx-VueCare

Onyx-VueCare Oct 12, 2015

I uploaded this code as a plugin to the wordpress and activated this plugin, nothing happened. So I went to this folder
/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/
and changed view-subscription.php

Original:

        <tr>
            <td><?php esc_html_e( 'Actions', 'woocommerce-subscriptions' ); ?></td>
            <td>
                <?php foreach ( $actions as $key => $action ) : ?>
                    <a href="<?php echo esc_url( $action['url'] ); ?>" class="button <?php echo sanitize_html_class( $key ) ?>"><?php echo esc_html( $action['name'] ); ?></a>
                <?php endforeach; ?>
            </td>
        </tr>

New:

        <tr>
            <td>Modify Subscriptions</td>
            <td>Contact Us</td>
        </tr>

Maybe someone can tell me how to make this snippet work instead.

I uploaded this code as a plugin to the wordpress and activated this plugin, nothing happened. So I went to this folder
/wp-content/plugins/woocommerce-subscriptions/templates/myaccount/
and changed view-subscription.php

Original:

        <tr>
            <td><?php esc_html_e( 'Actions', 'woocommerce-subscriptions' ); ?></td>
            <td>
                <?php foreach ( $actions as $key => $action ) : ?>
                    <a href="<?php echo esc_url( $action['url'] ); ?>" class="button <?php echo sanitize_html_class( $key ) ?>"><?php echo esc_html( $action['name'] ); ?></a>
                <?php endforeach; ?>
            </td>
        </tr>

New:

        <tr>
            <td>Modify Subscriptions</td>
            <td>Contact Us</td>
        </tr>

Maybe someone can tell me how to make this snippet work instead.

@thenbrent

This comment has been minimized.

Show comment Hide comment
@thenbrent

thenbrent Oct 13, 2015

I've just updated the gist to be compatible with Subscriptions 2.0.

Owner

thenbrent commented Oct 13, 2015

I've just updated the gist to be compatible with Subscriptions 2.0.

@Onyx-VueCare

This comment has been minimized.

Show comment Hide comment
@Onyx-VueCare

Onyx-VueCare Oct 16, 2015

Thank you so much, good sir! It works flawlessly. Also, you can add suspend there. I just tested it, it works as well.

Thank you again!!!

Thank you so much, good sir! It works flawlessly. Also, you can add suspend there. I just tested it, it works as well.

Thank you again!!!

@dsundmacher

This comment has been minimized.

Show comment Hide comment
@dsundmacher

dsundmacher Oct 28, 2015

This no longer works. It may need to be changed due to changes in the latest version of the plugin?

This no longer works. It may need to be changed due to changes in the latest version of the plugin?

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Nov 24, 2015

@dsundmacher you might be looking for an older version of this code if you are not using Subscriptions 2.0

See the revisions.

ghost commented Nov 24, 2015

@dsundmacher you might be looking for an older version of this code if you are not using Subscriptions 2.0

See the revisions.

@thenbrent

This comment has been minimized.

Show comment Hide comment
@thenbrent

thenbrent Jan 29, 2016

Also, you can add suspend there.

@Onyx-VueCare there is a setting to disable or restrict customer suspension: https://docs.woothemes.com/document/subscriptions/store-manager-guide/#misc-settings It's better to use that than custom code. 😄

Owner

thenbrent commented Jan 29, 2016

Also, you can add suspend there.

@Onyx-VueCare there is a setting to disable or restrict customer suspension: https://docs.woothemes.com/document/subscriptions/store-manager-guide/#misc-settings It's better to use that than custom code. 😄

@TheCrucible

This comment has been minimized.

Show comment Hide comment
@TheCrucible

TheCrucible Feb 20, 2016

Woo version 2.5.2 on my install and it works perfectly for me. Awesome little plugin, thanks Brent.

Woo version 2.5.2 on my install and it works perfectly for me. Awesome little plugin, thanks Brent.

@dberz

This comment has been minimized.

Show comment Hide comment
@dberz

dberz Apr 8, 2016

Can anyone recommend how to apply this functionality ONLY to subscriptions (products) of a particular CATEGORY?

dberz commented Apr 8, 2016

Can anyone recommend how to apply this functionality ONLY to subscriptions (products) of a particular CATEGORY?

@rvpatel

This comment has been minimized.

Show comment Hide comment
@rvpatel

rvpatel Aug 3, 2016

@thenbrent
Version: 2.0 how to manage
Remove cancel button which order has not completed 2 months please help us.

I have created code for old version related to 1.5.29.

function eg_remove_my_subscriptions_button($actions, $subscriptions) {
    foreach (array_reverse($subscriptions) as $subscription_key => $subscription) {
        if (!empty($subscription['product_id'])):
            $order_id = $subscription['order_id'];
            $id = $subscription['product_id'];
            $key = $subscription_key;

            $date1 = date_create($subscription['start_date']);
            $date2 = date_create();
            $difff = date_diff($date2, $date1);

            //echo '<pre>';
            //print_r($difff);                
            //echo 'months'.$difff->m;
            //echo 'days'.$difff->d;
            //echo 'year'.$difff->y;

            $limit_data = get_post_meta($id, 'cancel_subscribe_limit_months');
            if (isset($limit_data) && !empty($limit_data[0])):
                $ymonth = 0;
                if ($difff->Y > 1):
                    $ymonth = $difff->Y * 12;
                endif;

                $months_count = $ymonth + $difff->m;
                if ($months_count < $limit_data[0]) :

                    foreach ($actions as $subscription_key => $action_buttons):
                        if ($subscription_key == $key):
                            foreach ($action_buttons as $action => $button):
                                switch ($action):
                                    case 'cancel':
                                        unset($actions[$subscription_key][$action]);
                                        //$actions[ $subscription_key ]['cancel']['name'] = apply_filters( 'woocommerce_change_payment_button_text', __( $order_id, 'woocommerce-subscriptions' ) );
                                        break;
                                    default:
                                        error_log('-- $action = ' . print_r($action, true));
                                        break;
                                endswitch;
                            endforeach;
                        endif;
                    endforeach;
                endif;

            endif;
        endif;
    }
    return $actions;
}
add_filter('woocommerce_my_account_my_subscriptions_actions', 'eg_remove_my_subscriptions_button', 100, 2);

rvpatel commented Aug 3, 2016

@thenbrent
Version: 2.0 how to manage
Remove cancel button which order has not completed 2 months please help us.

I have created code for old version related to 1.5.29.

function eg_remove_my_subscriptions_button($actions, $subscriptions) {
    foreach (array_reverse($subscriptions) as $subscription_key => $subscription) {
        if (!empty($subscription['product_id'])):
            $order_id = $subscription['order_id'];
            $id = $subscription['product_id'];
            $key = $subscription_key;

            $date1 = date_create($subscription['start_date']);
            $date2 = date_create();
            $difff = date_diff($date2, $date1);

            //echo '<pre>';
            //print_r($difff);                
            //echo 'months'.$difff->m;
            //echo 'days'.$difff->d;
            //echo 'year'.$difff->y;

            $limit_data = get_post_meta($id, 'cancel_subscribe_limit_months');
            if (isset($limit_data) && !empty($limit_data[0])):
                $ymonth = 0;
                if ($difff->Y > 1):
                    $ymonth = $difff->Y * 12;
                endif;

                $months_count = $ymonth + $difff->m;
                if ($months_count < $limit_data[0]) :

                    foreach ($actions as $subscription_key => $action_buttons):
                        if ($subscription_key == $key):
                            foreach ($action_buttons as $action => $button):
                                switch ($action):
                                    case 'cancel':
                                        unset($actions[$subscription_key][$action]);
                                        //$actions[ $subscription_key ]['cancel']['name'] = apply_filters( 'woocommerce_change_payment_button_text', __( $order_id, 'woocommerce-subscriptions' ) );
                                        break;
                                    default:
                                        error_log('-- $action = ' . print_r($action, true));
                                        break;
                                endswitch;
                            endforeach;
                        endif;
                    endforeach;
                endif;

            endif;
        endif;
    }
    return $actions;
}
add_filter('woocommerce_my_account_my_subscriptions_actions', 'eg_remove_my_subscriptions_button', 100, 2);
@rvpatel

This comment has been minimized.

Show comment Hide comment
@rvpatel

rvpatel Aug 8, 2016

@thenbrent :
can u please guide to me for subscription renewal?

I have purchase one subscription and this one next payment date after 2 days so "nextpayment" process which one executed.
our system "plugin" or payment getway now i have used paypal & authorized.net cim

rvpatel commented Aug 8, 2016

@thenbrent :
can u please guide to me for subscription renewal?

I have purchase one subscription and this one next payment date after 2 days so "nextpayment" process which one executed.
our system "plugin" or payment getway now i have used paypal & authorized.net cim

@moussari

This comment has been minimized.

Show comment Hide comment
@moussari

moussari Nov 12, 2016

Hello,

I am not really a programmer per se.

I would like to remove the Action: Cancel from the my subscription.

what should i do? can someone help?

thanks

Hello,

I am not really a programmer per se.

I would like to remove the Action: Cancel from the my subscription.

what should i do? can someone help?

thanks

@davidleeschneider

This comment has been minimized.

Show comment Hide comment
@davidleeschneider

davidleeschneider Nov 28, 2016

Hi @moussari

Simply copy the above code (starting from line 2) and paste it into your theme's functions.php file.
The functions.php file is located in 'wp-content/themes/your-theme'

You have to make sure you remove the two slashes '//' for each button you you want to remove in line 22 to 28.

I hope that helps.

Regards,
David

Hi @moussari

Simply copy the above code (starting from line 2) and paste it into your theme's functions.php file.
The functions.php file is located in 'wp-content/themes/your-theme'

You have to make sure you remove the two slashes '//' for each button you you want to remove in line 22 to 28.

I hope that helps.

Regards,
David

@tanialeyvac

This comment has been minimized.

Show comment Hide comment
@tanialeyvac

tanialeyvac Jul 13, 2017

Hi, I'd like to hide the Cancel or Suspend button 5 days before the renew date.
Can someone help me complete the code with that conditional please?

Hi, I'd like to hide the Cancel or Suspend button 5 days before the renew date.
Can someone help me complete the code with that conditional please?

@crinive

This comment has been minimized.

Show comment Hide comment
@crinive

crinive Mar 15, 2018

Wonderful! I edited your code to disable the "Cancel" and "Suspend" buttons on specific subscription periods of 3, 6 and 12 months.

function disable_cancel_suspend( $actions, $subscription ) {
  
  $subtime = $subscription->billing_interval."-".$subscription->billing_period;
	if ( !in_array($subtime, array('3-month','6-month','1-year'), true ) ) {
    foreach ( $actions as $action_key => $action ) {
      switch ( $action_key ) {
      	case 'suspend':		// Hide "Suspend" button
      	case 'cancel':			// Hide "Cancel" button
      		unset( $actions[ $action_key ] );
      		break;
        default: 
          	error_log( '-- $action = ' . print_r( $action, true ) );
          	break;
      }
    }
  }
  
	return $actions;
}
add_filter( 'wcs_view_subscription_actions', 'disable_cancel_suspend', 100, 2);

crinive commented Mar 15, 2018

Wonderful! I edited your code to disable the "Cancel" and "Suspend" buttons on specific subscription periods of 3, 6 and 12 months.

function disable_cancel_suspend( $actions, $subscription ) {
  
  $subtime = $subscription->billing_interval."-".$subscription->billing_period;
	if ( !in_array($subtime, array('3-month','6-month','1-year'), true ) ) {
    foreach ( $actions as $action_key => $action ) {
      switch ( $action_key ) {
      	case 'suspend':		// Hide "Suspend" button
      	case 'cancel':			// Hide "Cancel" button
      		unset( $actions[ $action_key ] );
      		break;
        default: 
          	error_log( '-- $action = ' . print_r( $action, true ) );
          	break;
      }
    }
  }
  
	return $actions;
}
add_filter( 'wcs_view_subscription_actions', 'disable_cancel_suspend', 100, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment