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

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


Description Description


Parameters Parameters

$args

(array) (Optional) array of query argument data, see example of arguments below

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 ) ) {
				$statuses = array( $status );
			} elseif ( is_array( $status ) ) {
				$temp = array();
				foreach ( $status as $stat ) {
					if ( in_array( $stat, $statuses ) ) {
						$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(
			'count' => count( $query->posts ),
			'page' => $paged,
			'pages' => $query->max_num_pages,
			'transactions' => $transactions,
		);

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: