当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Subscriptions_Manager::trash_subscription方法代码示例

本文整理汇总了PHP中WC_Subscriptions_Manager::trash_subscription方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::trash_subscription方法的具体用法?PHP WC_Subscriptions_Manager::trash_subscription怎么用?PHP WC_Subscriptions_Manager::trash_subscription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Subscriptions_Manager的用法示例。


在下文中一共展示了WC_Subscriptions_Manager::trash_subscription方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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')) {
//.........这里部分代码省略.........
开发者ID:bulats,项目名称:chef,代码行数:101,代码来源:class-wc-subscriptions-list-table.php

示例2: 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);
 }
开发者ID:picassentviu,项目名称:AMMPro,代码行数:78,代码来源:class-wc-subscriptions-list-table.php


注:本文中的WC_Subscriptions_Manager::trash_subscription方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。