Automattic\WooCommerce\Internal\Admin\Orders

ListTable::prepare_items()publicWC 1.0

Prepares the list of items for displaying.

Метод класса: ListTable{}

Return

null. Nothing.

Usage

$ListTable = new ListTable();
$ListTable->prepare_items();

Код ListTable::prepare_items() WC 7.1.0

public function prepare_items() {
	$limit = $this->get_items_per_page( 'edit_orders_per_page' );

	$this->order_query_args = array(
		'limit'    => $limit,
		'page'     => $this->get_pagenum(),
		'paginate' => true,
		'type'     => 'shop_order',
	);

	$this->set_status_args();
	$this->set_order_args();
	$this->set_date_args();
	$this->set_customer_args();
	$this->set_search_args();

	/**
	 * Provides an opportunity to modify the query arguments used in the (Custom Order Table-powered) order list
	 * table.
	 *
	 * @since 6.9.0
	 *
	 * @param array $query_args Arguments to be passed to `wc_get_orders()`.
	 */
	$order_query_args = (array) apply_filters( 'woocommerce_order_list_table_prepare_items_query_args', $this->order_query_args );

	// We must ensure the 'paginate' argument is set.
	$order_query_args['paginate'] = true;

	$orders      = wc_get_orders( $order_query_args );
	$this->items = $orders->orders;

	$max_num_pages = $orders->max_num_pages;

	// Check in case the user has attempted to page beyond the available range of orders.
	if ( 0 === $max_num_pages && $this->order_query_args['page'] > 1 ) {
		$count_query_args          = $order_query_args;
		$count_query_args['page']  = 1;
		$count_query_args['limit'] = 1;
		$order_count               = wc_get_orders( $count_query_args );
		$max_num_pages             = (int) ceil( $order_count->total / $order_query_args['limit'] );
	}

	$this->set_pagination_args(
		array(
			'total_items' => $orders->total ?? 0,
			'per_page'    => $limit,
			'total_pages' => $max_num_pages,
		)
	);
}