本文整理汇总了PHP中WC_Subscriptions_Manager::can_subscription_be_changed_to方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::can_subscription_be_changed_to方法的具体用法?PHP WC_Subscriptions_Manager::can_subscription_be_changed_to怎么用?PHP WC_Subscriptions_Manager::can_subscription_be_changed_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::can_subscription_be_changed_to方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: maybe_change_users_subscription
/**
* 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;
}
}
示例2: change_payment_method_button
/**
* Add a "Change Payment Method" button to the "My Subscriptions" table.
*
* @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
* @since 1.4
*/
public static function change_payment_method_button($all_actions, $subscriptions)
{
foreach ($all_actions as $subscription_key => $actions) {
$order = new WC_Order($subscriptions[$subscription_key]['order_id']);
if (WC_Subscriptions_Manager::can_subscription_be_changed_to('new-payment-method', $subscription_key, get_current_user_id())) {
if (!WC_Subscriptions::is_woocommerce_pre_2_1()) {
// WC 2.1+
$url = add_query_arg(array('change_payment_method' => $subscription_key, 'order_id' => $order->id), $order->get_checkout_payment_url());
$url = wp_nonce_url($url, __FILE__);
} else {
$url = add_query_arg(array('change_payment_method' => $subscription_key, 'order_id' => $order->id, 'order' => $order->order_key), get_permalink(woocommerce_get_page_id('pay')));
$url = wp_nonce_url($url, __FILE__);
}
$all_actions[$subscription_key] = array('change_payment_method' => array('url' => $url, 'name' => __('Change Payment Method', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
}
}
return $all_actions;
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:25,代码来源:class-wc-subscriptions-change-payment-gateway.php
示例3: get_my_subscriptions_template
/**
* 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/');
}
示例4: process_actions
/**
* Handle activate & cancel actions for both individual items and bulk edit.
*
* @since 1.0
*/
public function process_actions()
{
$custom_actions = apply_filters('woocommerce_subscriptions_list_table_pre_process_actions', array('custom_action' => false, 'messages' => array(), 'error_messages' => array()));
if ($this->current_action() === false && $custom_actions['custom_action'] === false) {
return;
}
$messages = array();
$error_messages = array();
$query_args = array();
// Check if custom actions were taken by the filter - if so, it has handled the action and we only need to set the message/error messages
if ($custom_actions['custom_action'] !== false) {
$messages = $custom_actions['messages'];
$error_messages = $custom_actions['error_messages'];
} else {
if (isset($_GET['subscription'])) {
// Single subscription action
if (!wp_verify_nonce($_REQUEST['_wpnonce'], $_GET['subscription'])) {
wp_die(__('Action failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to($_GET['new_status'], $_GET['subscription'], $_GET['user'])) {
$error_messages[] = sprintf(__('Error: Subscription status can not be changed to "%s".', WC_Subscriptions::$text_domain), esc_html($_GET['new_status']));
} else {
switch ($_GET['new_status']) {
case 'active':
WC_Subscriptions_Manager::reactivate_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription activated.', WC_Subscriptions::$text_domain);
break;
case 'on-hold':
WC_Subscriptions_Manager::put_subscription_on_hold($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription put on-hold.', WC_Subscriptions::$text_domain);
break;
case 'cancelled':
WC_Subscriptions_Manager::cancel_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription cancelled.', WC_Subscriptions::$text_domain);
break;
case 'trash':
WC_Subscriptions_Manager::trash_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription trashed.', WC_Subscriptions::$text_domain);
break;
case 'deleted':
WC_Subscriptions_Manager::delete_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription deleted.', WC_Subscriptions::$text_domain);
break;
default:
$error_messages[] = __('Error: Unknown subscription status.', WC_Subscriptions::$text_domain);
break;
}
}
} else {
if (isset($_GET['subscription_keys'])) {
// Bulk actions
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-' . $this->_args['plural'])) {
wp_die(__('Bulk edit failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
$subscriptions = $_GET['subscription_keys'];
$subscription_count = 0;
$error_count = 0;
if (in_array($this->current_action(), array('trash', 'deleted'))) {
foreach ($subscriptions as $user_id => $subscription_keys) {
foreach ($subscription_keys as $subscription_key) {
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to($this->current_action(), $subscription_key, $user_id)) {
$error_count++;
} else {
$subscription_count++;
if ('trash' == $this->current_action()) {
WC_Subscriptions_Manager::trash_subscription($user_id, $subscription_key);
} else {
WC_Subscriptions_Manager::delete_subscription($user_id, $subscription_key);
}
}
}
}
if ($subscription_count > 0) {
if ('trash' == $this->current_action()) {
$messages[] = sprintf(_n('%d subscription moved to trash.', '%s subscriptions moved to trash.', $subscription_count, WC_Subscriptions::$text_domain), $subscription_count);
} else {
$messages[] = sprintf(_n('%d subscription deleted.', '%s subscriptions deleted.', $subscription_count, WC_Subscriptions::$text_domain), $subscription_count);
}
}
if ($error_count > 0) {
if ('trash' == $this->current_action()) {
$error_messages[] = sprintf(_n('%d subscription could not be trashed - is it active or on-hold? Try cancelling it before trashing it.', '%s subscriptions could not be trashed - are they active or on-hold? Try cancelling them before trashing.', $error_count, WC_Subscriptions::$text_domain), $error_count);
} else {
$error_messages[] = sprintf(_n('%d subscription could not deleted - is it active or on-hold? Try cancelling it before deleting.', '%s subscriptions could not deleted - are they active or on-hold? Try cancelling them before deleting.', $error_count, WC_Subscriptions::$text_domain), $error_count);
}
}
}
}
}
}
$message_nonce = wp_create_nonce(__FILE__);
set_transient($this->message_transient_prefix . $message_nonce, array('messages' => $messages, 'error_messages' => $error_messages), 60 * 60);
// Filter by a given customer or product?
if (isset($_GET['_customer_user']) || isset($_GET['_product_id'])) {
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-subscriptions')) {
//.........这里部分代码省略.........
示例5: add_switch_button
/**
* Adds a "Switch" button to the "My Subscriptions" table for those subscriptions can be upgraded/downgraded.
*
* @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
* @since 1.4
*/
public static function add_switch_button($all_actions, $subscriptions)
{
$user_id = get_current_user_id();
foreach ($all_actions as $subscription_key => $actions) {
if (WC_Subscriptions_Manager::can_subscription_be_changed_to('new-subscription', $subscription_key, $user_id)) {
$all_actions[$subscription_key] = array('switch' => array('url' => self::get_switch_link($subscription_key), 'name' => get_option(WC_Subscriptions_Admin::$option_prefix . '_switch_button_text', __('Switch Subscription', 'woocommerce-subscriptions')))) + $all_actions[$subscription_key];
}
}
return $all_actions;
}
示例6: add_switch_button
/**
* Adds a "Switch" button to the "My Subscriptions" table for those subscriptions can be upgraded/downgraded.
*
* @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
* @since 1.4
* @deprecated 2.0
*/
public static function add_switch_button($all_actions, $subscriptions)
{
_deprecated_function(__METHOD__, '2.0', __CLASS__ . '::print_switch_button( $subscription, $item )');
$user_id = get_current_user_id();
foreach ($all_actions as $subscription_key => $actions) {
if (WC_Subscriptions_Manager::can_subscription_be_changed_to('new-subscription', $subscription_key, $user_id)) {
$all_actions[$subscription_key] = array('switch' => array('url' => self::get_switch_link($subscription_key), 'name' => get_option(WC_Subscriptions_Admin::$option_prefix . '_switch_button_text', __('Upgrade or Downgrade', 'woocommerce-subscriptions')))) + $all_actions[$subscription_key];
}
}
return $all_actions;
}
示例7: process_actions
/**
* Handle activate & cancel actions for both individual items and bulk edit.
*
* @since 1.0
*/
public function process_actions()
{
if ($this->current_action() === false) {
return;
}
$messages = array();
$error_messages = array();
// Single subscription action
if (isset($_GET['subscription'])) {
if (!wp_verify_nonce($_REQUEST['_wpnonce'], $_GET['subscription'])) {
wp_die(__('Action failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to($_GET['new_status'], $_GET['subscription'], $_GET['user'])) {
$error_messages[] = sprintf(__('Error: Subscription status can not be changed to "%s".', WC_Subscriptions::$text_domain), esc_html($_GET['new_status']));
} else {
switch ($_GET['new_status']) {
case 'active':
WC_Subscriptions_Manager::reactivate_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription activated.', WC_Subscriptions::$text_domain);
break;
case 'suspended':
WC_Subscriptions_Manager::suspend_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription suspended.', WC_Subscriptions::$text_domain);
break;
case 'cancelled':
WC_Subscriptions_Manager::cancel_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription cancelled.', WC_Subscriptions::$text_domain);
break;
case 'trash':
WC_Subscriptions_Manager::trash_subscription($_GET['user'], $_GET['subscription']);
$messages[] = __('Subscription trashed.', WC_Subscriptions::$text_domain);
break;
default:
$error_messages[] = __('Error: Unknown subscription status.', WC_Subscriptions::$text_domain);
break;
}
}
} else {
if (isset($_GET['subscriptions'])) {
// Bulk actions
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-' . $this->_args['plural'])) {
wp_die(__('Bulk edit failed. Invalid Nonce.', WC_Subscriptions::$text_domain));
}
$subscriptions = $_GET[$this->_args['plural']];
$subscription_count = 0;
$error_count = 0;
if ('trash' === $this->current_action()) {
foreach ($subscriptions as $user_id => $subscription_keys) {
foreach ($subscription_keys as $subscription_key) {
if (!WC_Subscriptions_Manager::can_subscription_be_changed_to('trash', $subscription_key, $user_id)) {
$error_count++;
} else {
$subscription_count++;
WC_Subscriptions_Manager::trash_subscription($user_id, $subscription_key);
}
}
}
if ($subscription_count > 0) {
$messages[] = sprintf(_n('%d subscription moved to trash.', '%s subscriptions moved to trash.', $subscription_count), $subscription_count);
}
if ($error_count > 0) {
$error_messages[] = sprintf(_n('%d subscription could not be trashed - is it active or suspended? Try cancelling it before trashing it.', '%s subscriptions could not be trashed - are they active or suspended? Try cancelling them before trashing.', $error_count), $error_count);
}
}
}
}
$status = isset($_GET['status']) ? $_GET['status'] : 'all';
$message_nonce = wp_create_nonce(__FILE__);
set_transient($this->message_transient_prefix . $message_nonce, array('messages' => $messages, 'error_messages' => $error_messages), 60 * 60);
$redirect_to = add_query_arg(array('status' => $status, 'message' => $message_nonce), admin_url('admin.php?page=subscriptions'));
// Redirect to avoid performning actions on a page refresh
wp_safe_redirect($redirect_to);
}
示例8: esc_url
?>
<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
if (WC_Subscriptions_Manager::can_subscription_be_changed_to('cancelled', $subscription_key, $user_id)) {
?>
<a href="<?php
echo esc_url(WC_Subscriptions_Manager::get_users_change_status_link($subscription_key, 'cancelled'));
?>
" class="cancel" title="<?php
_e('Click to cancel this Subscription', WC_Subscriptions::$text_domain);
?>
">(<?php
_e('Cancel', WC_Subscriptions::$text_domain);
?>
)</a>
<?php
}
?>
</td>