LLMS_Order::get_transactions( array $args = array() )

Retrieve an array of transactions associated with the order according to supplied arguments


Parameters Parameters

$args

(array) (Optional) Hash of query argument data, ultimately passed to a WP_Query.

  • 'status'
    (string|string[]) Transaction post status or array of transaction post status. Defaults to "any".
  • 'type'
    (string|string[]) Transaction types or array of transaction types. Defaults to "any". Accepts "recurring", "single", or "trial".
  • 'per_page'
    (int) Number of transactions to include in the return. Default 50.
  • 'paged'
    (int) Result set page number.
  • 'order'
    (string) Result set order. Default "DESC". Accepts "DESC" or "ASC".
  • 'orderby'
    (string) Result set ordering field. Default "date".

Default value: array()


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/models/model.llms.order.php

	public function get_transactions( $args = array() ) {

		extract(
			wp_parse_args(
				$args,
				array(
					'status'   => 'any', // String or array or post statuses.
					'type'     => 'any', // String or array of transaction types [recurring|single|trial].
					'per_page' => 50, // Int, number of transactions to return.
					'paged'    => 1, // Int, page number of transactions to return.
					'order'    => 'DESC',
					'orderby'  => 'date', // Field to order results by.
				)
			)
		);

		// Assume any and use this to check for valid statuses.
		$statuses = llms_get_transaction_statuses();

		// Check statuses.
		if ( 'any' !== $statuses ) {

			// If status is a string, ensure it's a valid status.
			if ( is_string( $status ) && in_array( $status, $statuses, true ) ) {
				$statuses = array( $status );
			} elseif ( is_array( $status ) ) {
				$temp = array();
				foreach ( $status as $stat ) {
					if ( in_array( (string) $stat, $statuses, true ) ) {
						$temp[] = $stat;
					}
				}
				$statuses = $temp;
			}
		}

		// Setup type meta query.
		$types = array(
			'relation' => 'OR',
		);

		if ( 'any' === $type ) {
			$types[] = array(
				'key'   => $this->meta_prefix . 'payment_type',
				'value' => 'recurring',
			);
			$types[] = array(
				'key'   => $this->meta_prefix . 'payment_type',
				'value' => 'single',
			);
			$types[] = array(
				'key'   => $this->meta_prefix . 'payment_type',
				'value' => 'trial',
			);
		} elseif ( is_string( $type ) ) {
			$types[] = array(
				'key'   => $this->meta_prefix . 'payment_type',
				'value' => $type,
			);
		} elseif ( is_array( $type ) ) {
			foreach ( $type as $t ) {
				$types[] = array(
					'key'   => $this->meta_prefix . 'payment_type',
					'value' => $t,
				);
			}
		}

		// Execute the query.
		$query = new WP_Query(
			apply_filters(
				'llms_order_get_transactions_query',
				array(
					'meta_query'     => array(
						'relation' => 'AND',
						array(
							'key'   => $this->meta_prefix . 'order_id',
							'value' => $this->get( 'id' ),
						),
						$types,
					),
					'order'          => $order,
					'orderby'        => $orderby,
					'post_status'    => $statuses,
					'post_type'      => 'llms_transaction',
					'posts_per_page' => $per_page,
					'paged'          => $paged,
				)
			),
			$this,
			$status
		);

		$transactions = array();

		foreach ( $query->posts as $post ) {
			$transactions[ $post->ID ] = llms_get_post( $post );
		}

		return array(
			'total'        => $query->found_posts,
			'count'        => count( $query->posts ),
			'page'         => $paged,
			'pages'        => $query->max_num_pages,
			'transactions' => $transactions,
		);

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.2.0 Use stric type comparisons.
3.37.6 Add additional return property, total, which returns the total number of found transactions.
3.10.0 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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