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


PHP WC_Subscriptions::get_subscriptions方法代码示例

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


在下文中一共展示了WC_Subscriptions::get_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()
 {
     $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)));
 }
开发者ID:bulats,项目名称:chef,代码行数:42,代码来源: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()
 {
     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

示例3: woo_ce_get_subscriptions

function woo_ce_get_subscriptions( $args = array() ) {

	global $export;

	$limit_volume = -1;
	$offset = 0;

	if( $args ) {
		$limit_volume = ( isset( $args['limit_volume'] ) ? $args['limit_volume'] : -1 );
		$offset = $args['offset'];
		$subscription_status = ( isset( $args['subscription_status'] ) ? $args['subscription_status'] : array() );
		$subscription_product = ( isset( $args['subscription_product'] ) ? $args['subscription_product'] : array() );
	}

	$troubleshooting_url = 'http://www.visser.com.au/documentation/store-exporter-deluxe/usage/';

	// @mod - Will migrate to a WP_Query solution once feature is stable
/*
	$limit_volume = -1;
	$offset = 0;

	if( $args ) {
		$limit_volume = ( isset( $args['limit_volume'] ) ? $args['limit_volume'] : false );
		$offset = $args['offset'];
		$orderby = ( isset( $args['subscription_orderby'] ) ? $args['subscription_orderby'] : 'ID' );
		$order = ( isset( $args['subscription_order'] ) ? $args['subscription_order'] : 'ASC' );
	}
	$post_type = 'shop_order';
	$args = array(
		'post_type' => $post_type,
		'orderby' => $orderby,
		'order' => $order,
		'offset' => $offset,
		'posts_per_page' => $limit_volume,
		'post_status' => apply_filters( 'woo_ce_subscription_post_status', 'publish' ),
		'fields' => 'ids'
	);
	$subscription_ids = new WP_Query( $args );
	if( $subscription_ids->posts ) {
		foreach( $subscription_ids->posts as $subscription_id )
			$subscriptions[] = $subscription_id;
		$export->total_rows = count( $subscriptions );
	}
*/
	$output = array();

	// Check that WooCommerce Subscriptions exists
	if( !class_exists( 'WC_Subscriptions' ) || !class_exists( 'WC_Subscriptions_Manager' ) ) {
		$message = __( 'The WooCommerce Subscriptions class <code>WC_Subscriptions</code> or <code>WC_Subscriptions_Manager</code> could not be found, this is required to export Subscriptions.', 'woo_ce' ) . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __( 'Need help?', 'woo_ce' ) . '</a>)';
		woo_cd_admin_notice( $message, 'error' );
		return;
	} else {
		// Check that the get_all_users_subscriptions() function exists
		if( !method_exists( 'WC_Subscriptions_Manager', 'get_all_users_subscriptions' ) ) {
			$message = __( 'The WooCommerce Subscriptions method <code>WC_Subscriptions_Manager->get_all_users_subscriptions()</code> could not be found, this is required to export Subscriptions.', 'woo_ce' ) . ' (<a href="' . $troubleshooting_url . '" target="_blank">' . __( 'Need help?', 'woo_ce' ) . '</a>)';
			woo_cd_admin_notice( $message, 'error' );
			return;
		}
	}

	if( class_exists( 'WC_Subscriptions' ) ) {
		if( method_exists( 'WC_Subscriptions', 'get_subscriptions' ) ) {

			$args = array(
				'subscriptions_per_page' => $limit_volume,
				'offset' => $offset
			);

			// Allow other developers to bake in their own filters
			$args = apply_filters( 'woo_ce_get_subscriptions_args', $args );

			if( $subscriptions = WC_Subscriptions::get_subscriptions( $args ) ) {
				$subscription_statuses = woo_ce_get_subscription_statuses();
				foreach( $subscriptions as $subscription ) {
					$subscription = woo_ce_get_subscription_data( $subscription );
					$key = $subscription['key'];
					$output[$key] = apply_filters( 'woo_ce_subscription', (object)$subscription );
					// Filter by Subscription Status
					if( !empty( $subscription_status ) ) {
						if( !in_array( strtolower( $subscription['status'] ), $subscription_status ) ) {
							unset( $output[$key] );
							continue;
						}
					}
					// Filter by Subscription Product
					if( !empty( $subscription_product ) ) {
						if( !in_array( $subscription['product_id'], $subscription_product ) ) {
							unset( $output[$key] );
							continue;
						}
					}
				}
			}

		}
	}
	return $output;

}
开发者ID:helloworld-digital,项目名称:katemorgan,代码行数:99,代码来源:subscription.php


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