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.<br>

  • 'status'
    (string|string[]) Transaction post status or array of transaction post status. Defaults to "any".<br>
  • 'type'
    (string|string[]) Transaction types or array of transaction types. Defaults to "any".<br> Accepts "recurring", "single", or "trial".<br>
  • 'per_page'
    (int) Number of transactions to include in the return. Default 50.<br>
  • 'paged'
    (int) Result set page number.<br>
  • 'order'
    (string) Result set order. Default "DESC". Accepts "DESC" or "ASC".<br>
  • 'orderby'
    (string) Result set ordering field. Default "date".<br>
  • 'no_found_rows'
    (bool) Whether to skip counting the total rows found. Enabling can improve performance. Default false.<br>

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.
					'no_found_rows' => false,
				)
			)
		);

		// 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(
			/**
			 * Filters the order's transactions query aguments.
			 *
			 * @since 3.0.0
			 * @since 7.1.0 Added `$no_found_rows` arg.
			 *
			 * @param array $query_args {
			 *     Hash of query argument data passed to a WP_Query.
			 *
			 *     @type string|string[] $status        Transaction post status or array of transaction post status.
			 *                                          Defaults to "any".
			 *     @type string|string[] $type          Transaction types or array of transaction types.
			 *                                          Defaults to "any".
			 *                                          Accepts "recurring", "single", or "trial".
			 *     @type int             $per_page      Number of transactions to include in the return. Default `50`.
			 *     @type int             $paged         Result set page number.
			 *     @type string          $order         Result set order. Default "DESC". Accepts "DESC" or "ASC".
			 *     @type string          $orderby       Result set ordering field. Default "date".
			 *     @type bool            $no_found_rows Whether to skip counting the total rows found.
			 *                                          Enabling can improve performance. Default false.
			 * }
			 */
			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,
					'no_found_rows'  => $no_found_rows,
				)
			),
			$this,
			$status
		);

		$transactions = array();

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

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


Top ↑

Changelog Changelog

Changelog
Version Description
7.1.0 Added no_found_rows parameter.
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.