/** * Returns a URL including required parameters for an authenticated user to renew a subscription * * Deprecated because the use of a $subscription_key is deprecated. * * @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key() * @since 1.2 * @deprecated 2.0 */ public static function get_users_renewal_link($subscription_key, $role = 'parent') { _deprecated_function(__METHOD__, '2.0', 'wcs_get_users_resubscribe_link( $subscription )'); return wcs_get_users_resubscribe_link(wcs_get_subscription_from_key($subscription_key)); }
/** * Adjust renew membership URL for subscription-based memberships * * @since 1.0.0 * @param string $url Renew membership URL * @param WC_Memberships_User_Membership $user_membership * @return string Modified renew URL */ public function renew_membership_url($url, WC_Memberships_User_Membership $user_membership) { if ($this->has_membership_plan_subscription($user_membership->get_plan_id())) { // note that we must also check if order contains a subscription since users // can be manually-assigned to memberships and not have an associated subscription // 2.0 onwards if ($this->is_subscriptions_gte_2_0()) { if (wcs_order_contains_subscription($user_membership->get_order())) { $url = wcs_get_users_resubscribe_link($this->get_user_membership_subscription_id($user_membership->get_id())); } } else { if (WC_Subscriptions_Order::order_contains_subscription($user_membership->get_order())) { $subscription_key = $this->get_user_membership_subscription_key($user_membership->get_id()); $url = WC_Subscriptions_Renewal_Order::get_users_renewal_link($subscription_key); } } } return $url; }
/** * Retrieve available actions that a user can perform on the subscription * * @since 2.0 */ function wcs_get_all_user_actions_for_subscription($subscription, $user_id) { $actions = array(); if (user_can($user_id, 'edit_shop_subscription_status', $subscription->id)) { $admin_with_suspension_disallowed = current_user_can('manage_woocommerce') && '0' === get_option(WC_Subscriptions_Admin::$option_prefix . '_max_customer_suspensions', '0') ? true : false; $current_status = $subscription->get_status(); if ($subscription->can_be_updated_to('on-hold') && wcs_can_user_put_subscription_on_hold($subscription, $user_id) && !$admin_with_suspension_disallowed) { $actions['suspend'] = array('url' => wcs_get_users_change_status_link($subscription->id, 'on-hold', $current_status), 'name' => __('Suspend', 'woocommerce-subscriptions')); } elseif ($subscription->can_be_updated_to('active') && !$subscription->needs_payment()) { $actions['reactivate'] = array('url' => wcs_get_users_change_status_link($subscription->id, 'active', $current_status), 'name' => __('Reactivate', 'woocommerce-subscriptions')); } if (wcs_can_user_resubscribe_to($subscription, $user_id)) { $actions['resubscribe'] = array('url' => wcs_get_users_resubscribe_link($subscription), 'name' => __('Resubscribe', 'woocommerce-subscriptions')); } // Show button for subscriptions which can be cancelled and which may actually require cancellation (i.e. has a future payment) $next_payment = $subscription->get_time('next_payment'); if ($subscription->can_be_updated_to('cancelled') && !$subscription->is_one_payment() && ($next_payment > 0 || $subscription->has_status('on-hold') && empty($next_payment))) { $actions['cancel'] = array('url' => wcs_get_users_change_status_link($subscription->id, 'cancelled', $current_status), 'name' => _x('Cancel', 'an action on a subscription', 'woocommerce-subscriptions')); } } return apply_filters('wcs_view_subscription_actions', $actions, $subscription); }
/** * Returns a URL including required parameters for an authenticated user to renew a subscription by product ID. * * @param int $product_id The ID of a product post type. * @since 1.2 */ function wcs_get_users_resubscribe_link_for_product($product_id) { $renewal_url = ''; if (is_user_logged_in()) { foreach (wcs_get_users_subscriptions() as $subscription) { foreach ($subscription->get_items() as $line_item) { if (($line_item['product_id'] == $product_id || $line_item['variation_id'] == $product_id) && wcs_can_user_resubscribe_to($subscription)) { $renewal_url = wcs_get_users_resubscribe_link($subscription); break; } } } } return apply_filters('wcs_users_resubscribe_link_for_product', $renewal_url, $product_id); }