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


PHP WC_Subscriptions_Manager::search_subscriptions方法代码示例

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


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

示例1: prepare_items

 /**
  * Get, sort and filter subscriptions for display.
  *
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  * @since 1.0
  */
 function prepare_items()
 {
     global $wcs_list_table_statuses;
     $screen = get_current_screen();
     $per_page = $this->get_items_per_page($screen->get_option('per_page', 'option'), 10);
     $paged = isset($_GET['paged']) ? $_GET['paged'] : 1;
     $this->get_column_info();
     $status_to_show = isset($_GET['status']) ? $_GET['status'] : 'all';
     if (isset($_REQUEST['s']) || !empty($_REQUEST['orderby']) && 'next_payment_date' === $_REQUEST['orderby']) {
         @set_time_limit(300);
         $subscriptions = $wcs_list_table_statuses = array();
         // It's a search
         if (isset($_REQUEST['s'])) {
             $subscriptions_grouped_by_user = WC_Subscriptions_Manager::search_subscriptions($_REQUEST['s']);
         } else {
             // Order by next payment date
             $subscriptions_grouped_by_user = WC_Subscriptions_Manager::get_all_users_subscriptions();
         }
         foreach ($subscriptions_grouped_by_user as $user_id => $users_subscriptions) {
             // Filter by a certain customer?
             if (isset($_GET['_customer_user']) && (int) $user_id !== (int) $_GET['_customer_user']) {
                 continue;
             }
             foreach ($users_subscriptions as $subscription_key => $subscription) {
                 // Filter by a certain product?
                 if (isset($_GET['_product_id']) && (int) $subscription['product_id'] !== (int) $_GET['_product_id']) {
                     continue;
                 }
                 $wcs_list_table_statuses[$subscription['status']] = isset($wcs_list_table_statuses[$subscription['status']]) ? $wcs_list_table_statuses[$subscription['status']] + 1 : 1;
                 if ($status_to_show == $subscription['status'] || $status_to_show == 'all' && $subscription['status'] != 'trash') {
                     $subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
                 }
             }
         }
         // If we have a request for a status that does not exist, default to all subscriptions
         if (!isset($wcs_list_table_statuses[$status_to_show])) {
             if ($status_to_show != 'all') {
                 $status_to_show = $_GET['status'] = 'all';
                 foreach ($subscriptions_grouped_by_user as $user_id => $users_subscriptions) {
                     // Filter by a certain customer?
                     if (isset($_GET['_customer_user']) && (int) $user_id !== (int) $_GET['_customer_user']) {
                         continue;
                     }
                     foreach ($users_subscriptions as $subscription_key => $subscription) {
                         // Filter by a certain product?
                         if (isset($_GET['_product_id']) && (int) $subscription['product_id'] !== (int) $_GET['_product_id']) {
                             continue;
                         }
                         $subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
                     }
                 }
             } else {
                 $_GET['status'] = 'all';
             }
         }
         ksort($wcs_list_table_statuses);
         $wcs_list_table_statuses = array('all' => array_sum($wcs_list_table_statuses)) + $wcs_list_table_statuses;
         if (isset($wcs_list_table_statuses['trash'])) {
             $wcs_list_table_statuses['all'] = $wcs_list_table_statuses['all'] - $wcs_list_table_statuses['trash'];
         }
         $total_items = count($subscriptions);
         @usort($subscriptions, array(&$this, 'sort_subscriptions'));
         // Need to suppress warnings due to PHP bug here: https://bugs.php.net/bug.php?id=50688
         $subscriptions = array_slice($subscriptions, ($paged - 1) * $per_page, $per_page);
     } else {
         $subscriptions_query = array('paged' => $paged, 'subscriptions_per_page' => $per_page, 'subscription_status' => $status_to_show, 'order' => !empty($_REQUEST['order']) ? strtoupper($_REQUEST['order']) : 'DESC', 'orderby' => !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : '_subscription_start_date');
         // Filter by a certain customer?
         if (isset($_GET['_customer_user']) && !empty($_GET['_customer_user'])) {
             $subscriptions_query['customer_id'] = $_GET['_customer_user'];
         }
         // Filter by a certain product?
         if (isset($_GET['_product_id']) && !empty($_GET['_product_id'])) {
             $subscriptions_query['product_id'] = $_GET['_product_id'];
         }
         $subscriptions = WC_Subscriptions::get_subscriptions($subscriptions_query);
         $wcs_list_table_statuses = WC_Subscriptions::get_subscription_status_counts();
         if (isset($wcs_list_table_statuses['trash'])) {
             $wcs_list_table_statuses['all'] = $wcs_list_table_statuses['all'] - $wcs_list_table_statuses['trash'];
         }
         if ('all' === $status_to_show && !isset($subscriptions_query['customer_id']) && !isset($subscriptions_query['product_id'])) {
             $total_items = $wcs_list_table_statuses['all'];
         } else {
             $total_items = WC_Subscriptions::get_subscription_count($subscriptions_query);
         }
     }
     // Add sorted & sliced data to the items property to be used by the rest of the class
     $this->items = $subscriptions;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:100,代码来源:class-wc-subscriptions-list-table.php

示例2: prepare_items

 /**
  * Get, sort and filter subscriptions for display.
  *
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  * @since 1.0
  */
 function prepare_items()
 {
     $screen = get_current_screen();
     $per_page = $this->get_items_per_page($screen->get_option('per_page', 'option'), 10);
     $this->get_column_info();
     $this->process_actions();
     if (isset($_REQUEST['s'])) {
         $subscriptions_grouped_by_user = WC_Subscriptions_Manager::search_subscriptions($_REQUEST['s']);
     } elseif (isset($_GET['_customer_user']) || isset($_GET['_product_id'])) {
         if (isset($_GET['_customer_user']) && !empty($_GET['_customer_user'])) {
             $subscriptions_grouped_by_user = array($_GET['_customer_user'] => WC_Subscriptions_Manager::get_users_subscriptions($_GET['_customer_user']));
         } else {
             $subscriptions_grouped_by_user = WC_Subscriptions_Manager::get_all_users_subscriptions();
         }
         if (isset($_GET['_product_id']) && !empty($_GET['_product_id'])) {
             foreach ($subscriptions_grouped_by_user as $user_id => $subscriptions) {
                 foreach ($subscriptions as $subscription_key => $subscription) {
                     if ($subscription['product_id'] == intval($_GET['_product_id'])) {
                         continue;
                     }
                     $order_item = WC_Subscriptions_Order::get_item_by_product_id($subscription['order_id'], $subscription['product_id']);
                     if (isset($order_item['variation_id']) && $order_item['variation_id'] == intval($_GET['_product_id'])) {
                         continue;
                     }
                     unset($subscriptions_grouped_by_user[$user_id][$subscription_key]);
                 }
             }
         }
     } else {
         $subscriptions_grouped_by_user = WC_Subscriptions_Manager::get_all_users_subscriptions();
     }
     $status_to_show = isset($_GET['status']) ? $_GET['status'] : 'all';
     // Reformat the subscriptions grouped by user to be usable by each row
     $subscriptions = array();
     $this->statuses = array();
     foreach ($subscriptions_grouped_by_user as $user_id => $users_subscriptions) {
         foreach ($users_subscriptions as $subscription_key => $subscription) {
             $this->statuses[$subscription['status']] = isset($this->statuses[$subscription['status']]) ? $this->statuses[$subscription['status']] + 1 : 1;
             $all_subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
             if ($status_to_show == $subscription['status'] || $status_to_show == 'all' && $subscription['status'] != 'trash') {
                 $subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
             }
         }
     }
     // If we have a request for a status that does not exist, default to all subscriptions
     if (!isset($this->statuses[$status_to_show])) {
         if ($status_to_show != 'all') {
             $status_to_show = $_GET['status'] = 'all';
             foreach ($all_subscriptions as $subscription_key => $subscription) {
                 if ($all_subscriptions[$subscription_key]['status'] != 'trash') {
                     $subscriptions = $subscriptions + array($subscription_key => $subscription);
                 }
             }
         } else {
             $_GET['status'] = 'all';
         }
     }
     ksort($this->statuses);
     $this->statuses = array('all' => array_sum($this->statuses)) + $this->statuses;
     if (isset($this->statuses['trash'])) {
         $this->statuses['all'] = $this->statuses['all'] - $this->statuses['trash'];
     }
     usort($subscriptions, array(&$this, 'sort_subscriptions'));
     // Add sorted & sliced data to the items property to be used by the rest of the class
     $this->items = array_slice($subscriptions, ($this->get_pagenum() - 1) * $per_page, $per_page);
     $total_items = count($subscriptions);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
开发者ID:bulats,项目名称:chef,代码行数:79,代码来源:class-wc-subscriptions-list-table.php

示例3: prepare_items

 /**
  * Get, sort and filter subscriptions for display.
  *
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  * @since 1.0
  */
 function prepare_items()
 {
     $per_page = 10;
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
     $this->process_actions();
     if (isset($_REQUEST['s'])) {
         $subscriptions_grouped_by_user = WC_Subscriptions_Manager::search_subscriptions($_REQUEST['s']);
     } else {
         $subscriptions_grouped_by_user = WC_Subscriptions_Manager::get_all_users_subscriptions();
     }
     $status_to_show = isset($_GET['status']) ? $_GET['status'] : 'all';
     // Reformat the subscriptions grouped by user to be usable by each row
     $subscriptions = array();
     $this->statuses = array();
     foreach ($subscriptions_grouped_by_user as $user_id => $users_subscriptions) {
         foreach ($users_subscriptions as $subscription_key => $subscription) {
             $this->statuses[$subscription['status']] = isset($this->statuses[$subscription['status']]) ? $this->statuses[$subscription['status']] + 1 : 1;
             $all_subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
             if ($status_to_show == $subscription['status'] || $status_to_show == 'all' && $subscription['status'] != 'trash') {
                 $subscriptions[$subscription_key] = $subscription + array('user_id' => $user_id, 'subscription_key' => $subscription_key);
             }
         }
     }
     // If we have a request for a status that does not exist, default to all subscriptions
     if (!isset($this->statuses[$status_to_show])) {
         if ($status_to_show != 'all') {
             $status_to_show = $_GET['status'] = 'all';
             foreach ($all_subscriptions as $subscription_key => $subscription) {
                 if ($all_subscriptions[$subscription_key]['status'] != 'trash') {
                     $subscriptions = $subscriptions + array($subscription_key => $subscription);
                 }
             }
         } else {
             $_GET['status'] = 'all';
         }
     }
     ksort($this->statuses);
     $this->statuses = array('all' => array_sum($this->statuses)) + $this->statuses;
     if (isset($this->statuses['trash'])) {
         $this->statuses['all'] = $this->statuses['all'] - $this->statuses['trash'];
     }
     usort($subscriptions, array(&$this, 'sort_subscriptions'));
     // Add sorted & sliced data to the items property to be used by the rest of the class
     $this->items = array_slice($subscriptions, ($this->get_pagenum() - 1) * $per_page, $per_page);
     $total_items = count($subscriptions);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:58,代码来源:class-wc-subscriptions-list-table.php


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