本文整理汇总了PHP中WC_Subscriptions_Manager::suspend_subscription方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::suspend_subscription方法的具体用法?PHP WC_Subscriptions_Manager::suspend_subscription怎么用?PHP WC_Subscriptions_Manager::suspend_subscription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::suspend_subscription方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}