本文整理汇总了PHP中WC_Subscriptions::get_subscription_status_counts方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions::get_subscription_status_counts方法的具体用法?PHP WC_Subscriptions::get_subscription_status_counts怎么用?PHP WC_Subscriptions::get_subscription_status_counts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions
的用法示例。
在下文中一共展示了WC_Subscriptions::get_subscription_status_counts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)));
}
示例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);
$paged = isset($_GET['paged']) ? $_GET['paged'] : 1;
$this->get_column_info();
$this->process_actions();
$status_to_show = isset($_GET['status']) ? $_GET['status'] : 'all';
$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);
$total_items = WC_Subscriptions::get_subscription_count($subscriptions_query);
$this->statuses = array();
foreach ($subscriptions as $subscription) {
$this->statuses[$subscription['status']] = isset($this->statuses[$subscription['status']]) ? $this->statuses[$subscription['status']] + 1 : 1;
}
$this->statuses = WC_Subscriptions::get_subscription_status_counts();
if (isset($this->statuses['trash'])) {
$this->statuses['all'] = $this->statuses['all'] - $this->statuses['trash'];
}
// 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)));
}