/**
  * Loads the my-subscriptions.php template on the My Account page.
  *
  * @since 1.0
  */
 public static function get_my_subscriptions_template()
 {
     $subscriptions = WC_Subscriptions_Manager::get_users_subscriptions();
     $user_id = get_current_user_id();
     $all_actions = array();
     foreach ($subscriptions as $subscription_key => $subscription_details) {
         $actions = array();
         if ($subscription_details['status'] == 'trash') {
             unset($subscriptions[$subscription_key]);
             continue;
         }
         $admin_with_suspension_disallowed = current_user_can('manage_woocommerce') && 0 == get_option(WC_Subscriptions_Admin::$option_prefix . '_max_customer_suspensions', 0) ? true : false;
         if (WC_Subscriptions_Manager::can_subscription_be_changed_to('on-hold', $subscription_key, $user_id) && WC_Subscriptions_Manager::current_user_can_suspend_subscription($subscription_key) && !$admin_with_suspension_disallowed) {
             $actions['suspend'] = array('url' => WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'on-hold'), 'name' => __('Suspend', 'woocommerce-subscriptions'));
         } elseif (WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id) && !WC_Subscriptions_Manager::subscription_requires_payment($subscription_key, $user_id)) {
             $actions['reactivate'] = array('url' => WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'active'), 'name' => __('Reactivate', 'woocommerce-subscriptions'));
         }
         if (WC_Subscriptions_Renewal_Order::can_subscription_be_renewed($subscription_key, $user_id)) {
             $actions['renew'] = array('url' => WC_Subscriptions_Renewal_Order::get_users_renewal_link($subscription_key), 'name' => __('Renew', 'woocommerce-subscriptions'));
         }
         $renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders($subscription_details['order_id'], 'ID');
         $last_order_id = end($renewal_orders);
         if ($last_order_id) {
             $renewal_order = new WC_Order($last_order_id);
             if (WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id) && in_array($renewal_order->status, array('pending', 'failed')) && !is_numeric(get_post_meta($renewal_order->id, '_failed_order_replaced_by', true))) {
                 $actions['pay'] = array('url' => $renewal_order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce-subscriptions'));
             }
         } else {
             // Check if the master order still needs to be paid
             $order = new WC_Order($subscription_details['order_id']);
             if ('pending' == $order->status && WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id)) {
                 $actions['pay'] = array('url' => $order->get_checkout_payment_url(), 'name' => __('Pay', 'woocommerce-subscriptions'));
             }
         }
         if (WC_Subscriptions_Manager::can_subscription_be_changed_to('cancelled', $subscription_key, $user_id) && $subscription_details['interval'] != $subscription_details['length']) {
             $actions['cancel'] = array('url' => WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'cancelled'), 'name' => __('Cancel', 'woocommerce-subscriptions'));
         }
         $all_actions[$subscription_key] = $actions;
     }
     $all_actions = apply_filters('woocommerce_my_account_my_subscriptions_actions', $all_actions, $subscriptions);
     woocommerce_get_template('myaccount/my-subscriptions.php', array('subscriptions' => $subscriptions, 'actions' => $all_actions, 'user_id' => $user_id), '', plugin_dir_path(__FILE__) . 'templates/');
 }
 /**
  * Checks if the current request is by a user to change the status of their subscription, and if it is
  * validate the subscription cancellation request and maybe processes the cancellation. 
  * 
  * @since 1.0
  */
 public static function maybe_change_users_subscription()
 {
     global $woocommerce;
     if (isset($_GET['change_subscription_to']) && isset($_GET['subscription_key']) && isset($_GET['_wpnonce'])) {
         $user_id = get_current_user_id();
         $subscription = self::get_users_subscription($user_id, $_GET['subscription_key']);
         if (wp_verify_nonce($_GET['_wpnonce'], $_GET['subscription_key']) === false) {
             $woocommerce->add_error(sprintf(__('That subscription can not be changed to %s. Please contact us if you need assistance.', WC_Subscriptions::$text_domain), $_GET['change_subscription_to']));
         } elseif (empty($subscription)) {
             $woocommerce->add_error(__('That doesn\'t appear to be one of your subscriptions.', WC_Subscriptions::$text_domain));
         } elseif (!WC_Subscriptions_Manager::can_subscription_be_changed_to($_GET['change_subscription_to'], $_GET['subscription_key'], $user_id)) {
             $woocommerce->add_error(sprintf(__('That subscription can not be changed to %s. Please contact us if you need assistance.', WC_Subscriptions::$text_domain), $_GET['change_subscription_to']));
         } elseif (!in_array($_GET['change_subscription_to'], array('active', 'on-hold', 'cancelled'))) {
             $woocommerce->add_error(sprintf(__('Unknown subscription status: "%s". Please contact us if you need assistance.', WC_Subscriptions::$text_domain), $_GET['change_subscription_to']));
         } else {
             switch ($_GET['change_subscription_to']) {
                 case 'active':
                     if (WC_Subscriptions_Manager::subscription_requires_payment($_GET['subscription_key'], $user_id)) {
                         $woocommerce->add_error(sprintf(__('You can not reactive that subscription until paying to renew it. Please contact us if you need assistance.', WC_Subscriptions::$text_domain), $_GET['change_subscription_to']));
                     } else {
                         self::reactivate_subscription($user_id, $_GET['subscription_key']);
                         $status_message = __('reactivated', WC_Subscriptions::$text_domain);
                     }
                     break;
                 case 'on-hold':
                     if (self::current_user_can_suspend_subscription($_GET['subscription_key'])) {
                         self::put_subscription_on_hold($user_id, $_GET['subscription_key']);
                         $status_message = __('suspended', WC_Subscriptions::$text_domain);
                     } else {
                         $woocommerce->add_error(sprintf(__('You can not suspend that subscription - the suspension limit has been reached. Please contact us if you need assistance.', WC_Subscriptions::$text_domain), $_GET['change_subscription_to']));
                     }
                     break;
                 case 'cancelled':
                     self::cancel_subscription($user_id, $_GET['subscription_key']);
                     $status_message = __('cancelled', WC_Subscriptions::$text_domain);
                     break;
             }
             if (isset($status_message)) {
                 $order = new WC_Order($subscription['order_id']);
                 $order->add_order_note(sprintf(__('The status of subscription %s was changed to %s by the subscriber from their account page.', WC_Subscriptions::$text_domain), $_GET['subscription_key'], $_GET['change_subscription_to']));
                 $woocommerce->add_message(sprintf(__('Your subscription has been %s.', WC_Subscriptions::$text_domain), $status_message));
             }
         }
         wp_safe_redirect(get_permalink(woocommerce_get_page_id('myaccount')));
         exit;
     }
 }
        ?>
				<?php 
        if (WC_Subscriptions_Manager::can_subscription_be_changed_to('on-hold', $subscription_key, $user_id)) {
            ?>
				<a href="<?php 
            echo esc_url(WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'on-hold'));
            ?>
" class="on-hold" title="<?php 
            _e('Click to put this subscription on-hold', WC_Subscriptions::$text_domain);
            ?>
">(<?php 
            _e('Suspend', WC_Subscriptions::$text_domain);
            ?>
)</a>
				<?php 
        } elseif (!WC_Subscriptions_Manager::subscription_requires_payment($subscription_key, $user_id) && WC_Subscriptions_Manager::can_subscription_be_changed_to('active', $subscription_key, $user_id)) {
            ?>
				<a href="<?php 
            echo esc_url(WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'active'));
            ?>
" class="activate" title="<?php 
            _e('Click to reactivate this subscription', WC_Subscriptions::$text_domain);
            ?>
">(<?php 
            _e('Reactivate', WC_Subscriptions::$text_domain);
            ?>
)</a>
				<?php 
        }
        ?>
				<?php