Customer::get_orders( int $page = 1, int $limit = 12 )

Summary

Get the most recent orders on the account. Each will include at least one product (useful for finding featured images), but is not guaranteed to include all.


Description

WARNING: This function is heavy on API calls. One call for the order list, plus another for each order in the list.


Parameters

$page

(int) (Optional)

Default value: 1

$limit

(int) (Optional)

Default value: 12


Return

(array)


Source

File: src/BigCommerce/Accounts/Customer.php

	public function get_orders( $page = 1, $limit = 12 ) {
		$customer_id = $this->get_customer_id();
		if ( ! $customer_id ) {
			return [];
		}

		try {
			$orders = Client::getOrders( [
				'customer_id' => $customer_id,
				'sort'        => 'date_created:desc',
				'limit'       => $limit,
				'page'        => $page,
			] ) ?: [];
			$orders = array_map( function ( Order $order ) {
				$products = $this->get_order_products( $order->id ) ?: [];

				$order = get_object_vars( $order->getCreateFields() );

				$order['products'] = $products;

				return $order;
			}, $orders );

			return $orders;
		} catch ( \Exception $e ) {
			return [];
		}
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.